home *** CD-ROM | disk | FTP | other *** search
/ The Utilities Experience / The Utilities Experience - Volume 1.iso / software / misc / o-z / x-windows / mesa-amiwin / src / eval2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-30  |  73.1 KB  |  2,875 lines

  1. /* eval2.c */
  2.  
  3. /*
  4.  * Mesa 3-D graphics library
  5.  * Version:  1.2
  6.  * Copyright (C) 1995  Brian Paul  (brianp@ssec.wisc.edu)
  7.  *
  8.  * This library is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU Library General Public
  10.  * License as published by the Free Software Foundation; either
  11.  * version 2 of the License, or (at your option) any later version.
  12.  *
  13.  * This library is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.  * Library General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU Library General Public
  19.  * License along with this library; if not, write to the Free
  20.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  */
  22.  
  23.  
  24. /*
  25. $Id: eval2.c,v 1.8 1995/11/09 16:57:28 brianp Exp $
  26.  
  27. $Log: eval2.c,v $
  28.  * Revision 1.8  1995/11/09  16:57:28  brianp
  29.  * recompute strides in glMap[12][df] functions per Johan Nouvel
  30.  *
  31.  * Revision 1.7  1995/11/03  17:40:12  brianp
  32.  * removed unused variables
  33.  *
  34.  * Revision 1.6  1995/05/30  15:10:25  brianp
  35.  * added glGetMap[dfi]v() functions
  36.  *
  37.  * Revision 1.5  1995/05/29  21:22:57  brianp
  38.  * added glEvalCoord[12][df]v() functions
  39.  *
  40.  * Revision 1.4  1995/05/22  21:02:41  brianp
  41.  * Release 1.2
  42.  *
  43.  * Revision 1.3  1995/05/12  19:26:43  brianp
  44.  * replaced CC.Mode!=0 with INSIDE_BEGIN_END
  45.  *
  46.  * Revision 1.2  1995/03/04  19:29:44  brianp
  47.  * 1.1 beta revision
  48.  *
  49.  * Revision 1.1  1995/03/03  16:03:16  brianp
  50.  * Initial revision
  51.  *
  52.  */
  53.  
  54.  
  55. /*
  56.  * Version 2 of eval.c was written by
  57.  * Bernd Barsuhn (bdbarsuh@cip.informatik.uni-erlangen.de) and
  58.  * Volker Weiss (vrweiss@cip.informatik.uni-erlangen.de).
  59.  *
  60.  * My original implementation of evaluators was simplistic and didn't
  61.  * compute surface normal vectors properly.  Bernd and Volker applied
  62.  * used more sophisticated methods to get better results.
  63.  *
  64.  * Thanks guys!
  65.  */
  66.  
  67.  
  68.  
  69. #include <math.h>
  70. #include <stdlib.h>
  71. #include <string.h>
  72. #include "context.h"
  73. #include "draw.h"
  74. #include "list.h"
  75. #include "macros.h"
  76.  
  77.  
  78. /*
  79.  * Horner scheme for Bezier curves
  80.  * 
  81.  * Bezier curves can be computed via a Horner scheme.
  82.  * Horner is numerically less stable than the de Casteljau
  83.  * algorithm, but it is faster. For curves of degree n 
  84.  * the complexity of Horner is O(n) and de Casteljau is O(n^2).
  85.  * Since stability is not important for displaying curve 
  86.  * points I decided to use the Horner scheme.
  87.  *
  88.  * A cubic Bezier curve with control points b0, b1, b2, b3 can be 
  89.  * written as
  90.  *
  91.  *        (([3]        [3]     )     [3]       )     [3]
  92.  * c(t) = (([0]*s*b0 + [1]*t*b1)*s + [2]*t^2*b2)*s + [3]*t^2*b3
  93.  *
  94.  *                                           [n]
  95.  * where s=1-t and the binomial coefficients [i]. These can 
  96.  * be computed iteratively using the identity:
  97.  *
  98.  * [n]               [n  ]             [n]
  99.  * [i] = (n-i+1)/i * [i-1]     and     [0] = 1
  100.  */
  101.  
  102. static void
  103. horner_bezier_curve(GLfloat *cp, GLfloat *out, GLfloat t,
  104.                     GLuint dim, GLuint order)
  105. {
  106.   GLfloat s, powert;
  107.   GLuint i, k, bincoeff;
  108.  
  109.   if(order >= 2)
  110.   { 
  111.     bincoeff = order-1;
  112.     s = 1.0-t;
  113.  
  114.     for(k=0; k<dim; k++)
  115.       out[k] = s*cp[k] + bincoeff*t*cp[dim+k];
  116.  
  117.     for(i=2, cp+=2*dim, powert=t*t; i<order; i++, powert*=t, cp +=dim)
  118.     {
  119.       bincoeff *= order-i;
  120.       bincoeff /= i;
  121.  
  122.       for(k=0; k<dim; k++)
  123.         out[k] = s*out[k] + bincoeff*powert*cp[k];
  124.     }
  125.   }
  126.   else /* order=1 -> constant curve */
  127.   { 
  128.     for(k=0; k<dim; k++)
  129.       out[k] = cp[k];
  130.   } 
  131. }
  132.  
  133. /*
  134.  * Tensor product Bezier surfaces
  135.  *
  136.  * Again the Horner scheme is used to compute a point on a 
  137.  * TP Bezier surface. First a control polygon for a curve
  138.  * on the surface in one parameter direction is computed,
  139.  * then the point on the curve for the other parameter 
  140.  * direction is evaluated.
  141.  *
  142.  * To store the curve control polygon additional storage
  143.  * for max(uorder,vorder) points is needed in the 
  144.  * control net cn.
  145.  */
  146.  
  147. static void
  148. horner_bezier_surf(GLfloat *cn, GLfloat *out, GLfloat u, GLfloat v,
  149.                    GLuint dim, GLuint uorder, GLuint vorder)
  150. {
  151.   GLfloat *cp = cn + uorder*vorder*dim;
  152.   GLuint i, uinc = vorder*dim;
  153.  
  154.   if(vorder > uorder)
  155.   {
  156.     if(uorder >= 2)
  157.     { 
  158.       GLfloat s, poweru;
  159.       GLuint j, k, bincoeff;
  160.  
  161.       /* Compute the control polygon for the surface-curve in u-direction */
  162.       for(j=0; j<vorder; j++)
  163.       {
  164.         GLfloat *ucp = &cn[j*dim];
  165.  
  166.         /* Each control point is the point for parameter u on a */ 
  167.         /* curve defined by the control polygons in u-direction */
  168.     bincoeff = uorder-1;
  169.     s = 1.0-u;
  170.  
  171.     for(k=0; k<dim; k++)
  172.       cp[j*dim+k] = s*ucp[k] + bincoeff*u*ucp[uinc+k];
  173.  
  174.     for(i=2, ucp+=2*uinc, poweru=u*u; i<uorder; 
  175.             i++, poweru*=u, ucp +=uinc)
  176.     {
  177.       bincoeff *= uorder-i;
  178.           bincoeff /= i;
  179.  
  180.       for(k=0; k<dim; k++)
  181.         cp[j*dim+k] = s*cp[j*dim+k] + bincoeff*poweru*ucp[k];
  182.     }
  183.       }
  184.         
  185.       /* Evaluate curve point in v */
  186.       horner_bezier_curve(cp, out, v, dim, vorder);
  187.     }
  188.     else /* uorder=1 -> cn defines a curve in v */
  189.       horner_bezier_curve(cn, out, v, dim, vorder);
  190.   }
  191.   else /* vorder <= uorder */
  192.   {
  193.     if(vorder > 1)
  194.     {
  195.       GLuint i;
  196.  
  197.       /* Compute the control polygon for the surface-curve in u-direction */
  198.       for(i=0; i<uorder; i++, cn += uinc)
  199.       {
  200.     /* For constant i all cn[i][j] (j=0..vorder) are located */
  201.     /* on consecutive memory locations, so we can use        */
  202.     /* horner_bezier_curve to compute the control points     */
  203.  
  204.     horner_bezier_curve(cn, &cp[i*dim], v, dim, vorder);
  205.       }
  206.  
  207.       /* Evaluate curve point in u */
  208.       horner_bezier_curve(cp, out, u, dim, uorder);
  209.     }
  210.     else  /* vorder=1 -> cn defines a curve in u */
  211.       horner_bezier_curve(cn, out, u, dim, uorder);
  212.   }
  213. }
  214.  
  215. /*
  216.  * The direct de Casteljau algorithm is used when a point on the
  217.  * surface and the tangent directions spanning the tangent plane
  218.  * should be computed (this is needed to compute normals to the
  219.  * surface). In this case the de Casteljau algorithm approach is
  220.  * nicer because a point and the partial derivatives can be computed 
  221.  * at the same time. To get the correct tangent length du and dv
  222.  * must be multiplied with the (u2-u1)/uorder-1 and (v2-v1)/vorder-1. 
  223.  * Since only the directions are needed, this scaling step is omitted.
  224.  *
  225.  * De Casteljau needs additional storage for uorder*vorder
  226.  * values in the control net cn.
  227.  */
  228.  
  229. static void
  230. de_casteljau_surf(GLfloat *cn, GLfloat *out, GLfloat *du, GLfloat *dv,
  231.                   GLfloat u, GLfloat v, GLuint dim, 
  232.                   GLuint uorder, GLuint vorder)
  233. {
  234.   GLfloat *dcn = cn + uorder*vorder*dim;
  235.   GLfloat us = 1.0-u, vs = 1.0-v;
  236.   GLuint h, i, j, k;
  237.   GLuint minorder = uorder < vorder ? uorder : vorder;
  238.   GLuint uinc = vorder*dim;
  239.   GLuint dcuinc = vorder;
  240.  
  241.   /* Each component is evaluated separately to save buffer space  */
  242.   /* This does not drasticaly decrease the performance of the     */
  243.   /* algorithm. If additional storage for (uorder-1)*(vorder-1)   */
  244.   /* points would be available, the components could be accessed  */
  245.   /* in the innermost loop which could lead to less cache misses. */
  246.  
  247. #define CN(I,J,K) cn[(I)*uinc+(J)*dim+(K)] 
  248. #define DCN(I, J) dcn[(I)*dcuinc+(J)]
  249.   if(minorder < 3)
  250.   {
  251.     if(uorder==vorder)
  252.     {
  253.       for(k=0; k<dim; k++)
  254.       {
  255.     /* Derivative direction in u */
  256.     du[k] = vs*(CN(1,0,k) - CN(0,0,k)) +
  257.              v*(CN(1,1,k) - CN(0,1,k));
  258.  
  259.     /* Derivative direction in v */
  260.     dv[k] = us*(CN(0,1,k) - CN(0,0,k)) + 
  261.              u*(CN(1,1,k) - CN(1,0,k));
  262.  
  263.     /* bilinear de Casteljau step */
  264.         out[k] =  us*(vs*CN(0,0,k) + v*CN(0,1,k)) +
  265.                u*(vs*CN(1,0,k) + v*CN(1,1,k));
  266.       }
  267.     }
  268.     else if(minorder == uorder)
  269.     {
  270.       for(k=0; k<dim; k++)
  271.       {
  272.     /* bilinear de Casteljau step */
  273.     DCN(1,0) =    CN(1,0,k) -   CN(0,0,k);
  274.     DCN(0,0) = us*CN(0,0,k) + u*CN(1,0,k);
  275.  
  276.     for(j=0; j<vorder-1; j++)
  277.     {
  278.       /* for the derivative in u */
  279.       DCN(1,j+1) =    CN(1,j+1,k) -   CN(0,j+1,k);
  280.       DCN(1,j)   = vs*DCN(1,j)    + v*DCN(1,j+1);
  281.  
  282.       /* for the `point' */
  283.       DCN(0,j+1) = us*CN(0,j+1,k) + u*CN(1,j+1,k);
  284.       DCN(0,j)   = vs*DCN(0,j)    + v*DCN(0,j+1);
  285.     }
  286.         
  287.     /* remaining linear de Casteljau steps until the second last step */
  288.     for(h=minorder; h<vorder-1; h++)
  289.       for(j=0; j<vorder-h; j++)
  290.       {
  291.         /* for the derivative in u */
  292.         DCN(1,j) = vs*DCN(1,j) + v*DCN(1,j+1);
  293.  
  294.         /* for the `point' */
  295.         DCN(0,j) = vs*DCN(0,j) + v*DCN(0,j+1);
  296.       }
  297.  
  298.     /* derivative direction in v */
  299.     dv[k] = DCN(0,1) - DCN(0,0);
  300.  
  301.     /* derivative direction in u */
  302.     du[k] =   vs*DCN(1,0) + v*DCN(1,1);
  303.  
  304.     /* last linear de Casteljau step */
  305.     out[k] =  vs*DCN(0,0) + v*DCN(0,1);
  306.       }
  307.     }
  308.     else /* minorder == vorder */
  309.     {
  310.       for(k=0; k<dim; k++)
  311.       {
  312.     /* bilinear de Casteljau step */
  313.     DCN(0,1) =    CN(0,1,k) -   CN(0,0,k);
  314.     DCN(0,0) = vs*CN(0,0,k) + v*CN(0,1,k);
  315.     for(i=0; i<uorder-1; i++)
  316.     {
  317.       /* for the derivative in v */
  318.       DCN(i+1,1) =    CN(i+1,1,k) -   CN(i+1,0,k);
  319.       DCN(i,1)   = us*DCN(i,1)    + u*DCN(i+1,1);
  320.  
  321.       /* for the `point' */
  322.       DCN(i+1,0) = vs*CN(i+1,0,k) + v*CN(i+1,1,k);
  323.       DCN(i,0)   = us*DCN(i,0)    + u*DCN(i+1,0);
  324.     }
  325.         
  326.     /* remaining linear de Casteljau steps until the second last step */
  327.     for(h=minorder; h<uorder-1; h++)
  328.       for(i=0; i<uorder-h; i++)
  329.       {
  330.         /* for the derivative in v */
  331.         DCN(i,1) = us*DCN(i,1) + u*DCN(i+1,1);
  332.  
  333.         /* for the `point' */
  334.         DCN(i,0) = us*DCN(i,0) + u*DCN(i+1,0);
  335.       }
  336.  
  337.     /* derivative direction in u */
  338.     du[k] = DCN(1,0) - DCN(0,0);
  339.  
  340.     /* derivative direction in v */
  341.     dv[k] =   us*DCN(0,1) + u*DCN(1,1);
  342.  
  343.     /* last linear de Casteljau step */
  344.     out[k] =  us*DCN(0,0) + u*DCN(1,0);
  345.       }
  346.     }
  347.   }
  348.   else if(uorder == vorder)
  349.   {
  350.     for(k=0; k<dim; k++)
  351.     {
  352.       /* first bilinear de Casteljau step */
  353.       for(i=0; i<uorder-1; i++)
  354.       {
  355.     DCN(i,0) = us*CN(i,0,k) + u*CN(i+1,0,k);
  356.     for(j=0; j<vorder-1; j++)
  357.     {
  358.       DCN(i,j+1) = us*CN(i,j+1,k) + u*CN(i+1,j+1,k);
  359.       DCN(i,j)   = vs*DCN(i,j)    + v*DCN(i,j+1);
  360.     }
  361.       }
  362.  
  363.       /* remaining bilinear de Casteljau steps until the second last step */
  364.       for(h=2; h<minorder-1; h++)
  365.     for(i=0; i<uorder-h; i++)
  366.     {
  367.       DCN(i,0) = us*DCN(i,0) + u*DCN(i+1,0);
  368.       for(j=0; j<vorder-h; j++)
  369.       {
  370.         DCN(i,j+1) = us*DCN(i,j+1) + u*DCN(i+1,j+1);
  371.         DCN(i,j)   = vs*DCN(i,j)   + v*DCN(i,j+1);
  372.       }
  373.     }
  374.  
  375.       /* derivative direction in u */
  376.       du[k] = vs*(DCN(1,0) - DCN(0,0)) +
  377.            v*(DCN(1,1) - DCN(0,1));
  378.  
  379.       /* derivative direction in v */
  380.       dv[k] = us*(DCN(0,1) - DCN(0,0)) + 
  381.            u*(DCN(1,1) - DCN(1,0));
  382.  
  383.       /* last bilinear de Casteljau step */
  384.       out[k] =  us*(vs*DCN(0,0) + v*DCN(0,1)) +
  385.              u*(vs*DCN(1,0) + v*DCN(1,1));
  386.     }
  387.   }
  388.   else if(minorder == uorder)
  389.   {
  390.     for(k=0; k<dim; k++)
  391.     {
  392.       /* first bilinear de Casteljau step */
  393.       for(i=0; i<uorder-1; i++)
  394.       {
  395.     DCN(i,0) = us*CN(i,0,k) + u*CN(i+1,0,k);
  396.     for(j=0; j<vorder-1; j++)
  397.     {
  398.       DCN(i,j+1) = us*CN(i,j+1,k) + u*CN(i+1,j+1,k);
  399.       DCN(i,j)   = vs*DCN(i,j)    + v*DCN(i,j+1);
  400.     }
  401.       }
  402.  
  403.       /* remaining bilinear de Casteljau steps until the second last step */
  404.       for(h=2; h<minorder-1; h++)
  405.     for(i=0; i<uorder-h; i++)
  406.     {
  407.       DCN(i,0) = us*DCN(i,0) + u*DCN(i+1,0);
  408.       for(j=0; j<vorder-h; j++)
  409.       {
  410.         DCN(i,j+1) = us*DCN(i,j+1) + u*DCN(i+1,j+1);
  411.         DCN(i,j)   = vs*DCN(i,j)   + v*DCN(i,j+1);
  412.       }
  413.     }
  414.  
  415.       /* last bilinear de Casteljau step */
  416.       DCN(2,0) =    DCN(1,0) -   DCN(0,0);
  417.       DCN(0,0) = us*DCN(0,0) + u*DCN(1,0);
  418.       for(j=0; j<vorder-1; j++)
  419.       {
  420.     /* for the derivative in u */
  421.     DCN(2,j+1) =    DCN(1,j+1) -    DCN(0,j+1);
  422.     DCN(2,j)   = vs*DCN(2,j)    + v*DCN(2,j+1);
  423.     
  424.     /* for the `point' */
  425.     DCN(0,j+1) = us*DCN(0,j+1 ) + u*DCN(1,j+1);
  426.     DCN(0,j)   = vs*DCN(0,j)    + v*DCN(0,j+1);
  427.       }
  428.         
  429.       /* remaining linear de Casteljau steps until the second last step */
  430.       for(h=minorder; h<vorder-1; h++)
  431.     for(j=0; j<vorder-h; j++)
  432.     {
  433.       /* for the derivative in u */
  434.       DCN(2,j) = vs*DCN(2,j) + v*DCN(2,j+1);
  435.       
  436.       /* for the `point' */
  437.       DCN(0,j) = vs*DCN(0,j) + v*DCN(0,j+1);
  438.     }
  439.       
  440.       /* derivative direction in v */
  441.       dv[k] = DCN(0,1) - DCN(0,0);
  442.       
  443.       /* derivative direction in u */
  444.       du[k] =   vs*DCN(2,0) + v*DCN(2,1);
  445.       
  446.       /* last linear de Casteljau step */
  447.       out[k] =  vs*DCN(0,0) + v*DCN(0,1);
  448.     }
  449.   }
  450.   else /* minorder == vorder */
  451.   {
  452.     for(k=0; k<dim; k++)
  453.     {
  454.       /* first bilinear de Casteljau step */
  455.       for(i=0; i<uorder-1; i++)
  456.       {
  457.     DCN(i,0) = us*CN(i,0,k) + u*CN(i+1,0,k);
  458.     for(j=0; j<vorder-1; j++)
  459.     {
  460.       DCN(i,j+1) = us*CN(i,j+1,k) + u*CN(i+1,j+1,k);
  461.       DCN(i,j)   = vs*DCN(i,j)    + v*DCN(i,j+1);
  462.     }
  463.       }
  464.  
  465.       /* remaining bilinear de Casteljau steps until the second last step */
  466.       for(h=2; h<minorder-1; h++)
  467.     for(i=0; i<uorder-h; i++)
  468.     {
  469.       DCN(i,0) = us*DCN(i,0) + u*DCN(i+1,0);
  470.       for(j=0; j<vorder-h; j++)
  471.       {
  472.         DCN(i,j+1) = us*DCN(i,j+1) + u*DCN(i+1,j+1);
  473.         DCN(i,j)   = vs*DCN(i,j)   + v*DCN(i,j+1);
  474.       }
  475.     }
  476.  
  477.       /* last bilinear de Casteljau step */
  478.       DCN(0,2) =    DCN(0,1) -   DCN(0,0);
  479.       DCN(0,0) = vs*DCN(0,0) + v*DCN(0,1);
  480.       for(i=0; i<uorder-1; i++)
  481.       {
  482.     /* for the derivative in v */
  483.     DCN(i+1,2) =    DCN(i+1,1)  -   DCN(i+1,0);
  484.     DCN(i,2)   = us*DCN(i,2)    + u*DCN(i+1,2);
  485.     
  486.     /* for the `point' */
  487.     DCN(i+1,0) = vs*DCN(i+1,0)  + v*DCN(i+1,1);
  488.     DCN(i,0)   = us*DCN(i,0)    + u*DCN(i+1,0);
  489.       }
  490.       
  491.       /* remaining linear de Casteljau steps until the second last step */
  492.       for(h=minorder; h<uorder-1; h++)
  493.     for(i=0; i<uorder-h; i++)
  494.     {
  495.       /* for the derivative in v */
  496.       DCN(i,2) = us*DCN(i,2) + u*DCN(i+1,2);
  497.       
  498.       /* for the `point' */
  499.       DCN(i,0) = us*DCN(i,0) + u*DCN(i+1,0);
  500.     }
  501.       
  502.       /* derivative direction in u */
  503.       du[k] = DCN(1,0) - DCN(0,0);
  504.       
  505.       /* derivative direction in v */
  506.       dv[k] =   us*DCN(0,2) + u*DCN(1,2);
  507.       
  508.       /* last linear de Casteljau step */
  509.       out[k] =  us*DCN(0,0) + u*DCN(1,0);
  510.     }
  511.   }
  512. #undef DCN
  513. #undef CN
  514. }
  515.  
  516. /*
  517.  * Return the number of components per control point for any type of
  518.  * evaluator.  Return 0 if bad target.
  519.  */
  520.  
  521. static GLint components( GLenum target )
  522. {
  523.    switch (target) {
  524.       case GL_MAP1_VERTEX_3:        return 3;
  525.       case GL_MAP1_VERTEX_4:        return 4;
  526.       case GL_MAP1_INDEX:        return 1;
  527.       case GL_MAP1_COLOR_4:        return 4;
  528.       case GL_MAP1_NORMAL:        return 3;
  529.       case GL_MAP1_TEXTURE_COORD_1:    return 1;
  530.       case GL_MAP1_TEXTURE_COORD_2:    return 2;
  531.       case GL_MAP1_TEXTURE_COORD_3:    return 3;
  532.       case GL_MAP1_TEXTURE_COORD_4:    return 4;
  533.       case GL_MAP2_VERTEX_3:        return 3;
  534.       case GL_MAP2_VERTEX_4:        return 4;
  535.       case GL_MAP2_INDEX:        return 1;
  536.       case GL_MAP2_COLOR_4:        return 4;
  537.       case GL_MAP2_NORMAL:        return 3;
  538.       case GL_MAP2_TEXTURE_COORD_1:    return 1;
  539.       case GL_MAP2_TEXTURE_COORD_2:    return 2;
  540.       case GL_MAP2_TEXTURE_COORD_3:    return 3;
  541.       case GL_MAP2_TEXTURE_COORD_4:    return 4;
  542.       default:                return 0;
  543.    }
  544. }
  545.  
  546.  
  547.  
  548. /*
  549.  * Copy 1-parametric evaluator control points from user-specified 
  550.  * memory space to a buffer of contiguous control points.
  551.  * Input:  see glMap1f for details
  552.  * Return:  pointer to buffer of contiguous control points or NULL if out
  553.  *          of memory.
  554.  */
  555.  
  556. static GLfloat *copy_points1_f( GLenum target,
  557.                     GLint ustride, GLint uorder,
  558.                     const GLfloat *points )
  559. {
  560.    GLfloat *buffer, *p;
  561.    GLuint i, k, size = components(target);
  562.  
  563.    buffer = (GLfloat *) malloc(uorder * size * sizeof(GLfloat));
  564.  
  565.    if(buffer) 
  566.       for(i=0, p=buffer; i<uorder; i++, points+=ustride)
  567.     for(k=0; k<size; k++)
  568.       *p++ = points[k];
  569.  
  570.    return buffer;
  571. }
  572.  
  573.  
  574.  
  575. /*
  576.  * Same as above but convert doubles to floats.
  577.  */
  578.  
  579. static GLfloat *copy_points1_d( GLenum target,
  580.                     GLint ustride, GLint uorder,
  581.                     const GLdouble *points )
  582. {
  583.    GLfloat *buffer, *p;
  584.    GLuint i, k, size = components(target);
  585.  
  586.    buffer = (GLfloat *) malloc(uorder * size * sizeof(GLfloat));
  587.  
  588.    if(buffer)
  589.       for(i=0, p=buffer; i<uorder; i++, points+=ustride)
  590.     for(k=0; k<size; k++)
  591.       *p++ = (GLfloat) points[k];
  592.  
  593.    return buffer;
  594. }
  595.  
  596. /*
  597.  * Copy 2-parametric evaluator control points from user-specified 
  598.  * memory space to a buffer of contiguous control points.
  599.  * Additional memory is allocated to be used by the horner and
  600.  * de Casteljau evaluation schemes.
  601.  *
  602.  * Input:  see glMap2f for details
  603.  * Return:  pointer to buffer of contiguous control points or NULL if out
  604.  *          of memory.
  605.  */
  606.  
  607. static GLfloat *copy_points2_f( GLenum target,
  608.                     GLint ustride, GLint uorder,
  609.                     GLint vstride, GLint vorder,
  610.                     const GLfloat *points )
  611. {
  612.    GLfloat *buffer, *p;
  613.    GLuint i, j, k, size, dsize, hsize;
  614.    GLint uinc;
  615.  
  616.    size = components(target);
  617.  
  618.    /* max(uorder, vorder) additional points are used in      */
  619.    /* horner evaluation and uorder*vorder additional */
  620.    /* values are needed for de Casteljau                     */
  621.    dsize = (uorder == 2 && vorder == 2)? 0 : uorder*vorder;
  622.    hsize = (uorder > vorder ? uorder : vorder)*size;
  623.  
  624.    if(hsize>dsize)
  625.      buffer = (GLfloat *) malloc((uorder*vorder*size+hsize)*sizeof(GLfloat));
  626.    else
  627.      buffer = (GLfloat *) malloc((uorder*vorder*size+dsize)*sizeof(GLfloat));
  628.  
  629.    /* compute the increment value for the u-loop */
  630.    uinc = ustride - vorder*vstride;
  631.  
  632.    if (buffer) 
  633.       for (i=0, p=buffer; i<uorder; i++, points += uinc)
  634.      for (j=0; j<vorder; j++, points += vstride)
  635.         for (k=0; k<size; k++)
  636.            *p++ = points[k];
  637.  
  638.    return buffer;
  639. }
  640.  
  641.  
  642.  
  643. /*
  644.  * Same as above but convert doubles to floats.
  645.  */
  646.  
  647. static GLfloat *copy_points2_d(GLenum target,
  648.                    GLint ustride, GLint uorder,
  649.                    GLint vstride, GLint vorder,
  650.                    const GLdouble *points )
  651. {
  652.    GLfloat *buffer, *p;
  653.    GLuint i, j, k, size, hsize, dsize;
  654.    GLint uinc;
  655.  
  656.    size = components(target);
  657.  
  658.    /* max(uorder, vorder) additional points are used in      */
  659.    /* horner evaluation and uorder*vorder additional */
  660.    /* values are needed for de Casteljau                     */
  661.    dsize = (uorder == 2 && vorder == 2)? 0 : uorder*vorder;
  662.    hsize = (uorder > vorder ? uorder : vorder)*size;
  663.  
  664.    if(hsize>dsize)
  665.      buffer = (GLfloat *) malloc((uorder*vorder*size+hsize)*sizeof(GLfloat));
  666.    else
  667.      buffer = (GLfloat *) malloc((uorder*vorder*size+dsize)*sizeof(GLfloat));
  668.  
  669.    /* compute the increment value for the u-loop */
  670.    uinc = ustride - vorder*vstride;
  671.  
  672.    if (buffer) 
  673.       for (i=0, p=buffer; i<uorder; i++, points += uinc)
  674.      for (j=0; j<vorder; j++, points += vstride)
  675.         for (k=0; k<size; k++)
  676.            *p++ = (GLfloat) points[k];
  677.  
  678.    return buffer;
  679. }
  680.  
  681. /**********************************************************************/
  682. /*                            Internal                                */
  683. /**********************************************************************/
  684.  
  685.  
  686. /*
  687.  * Do one-time initialization for evaluators.
  688.  */
  689.  
  690. void gl_init_eval( void )
  691. {
  692.   static int init_flag = 0;
  693.  
  694.   /* Compute a table of nCr (combination) values used by the
  695.    * Bernstein polynomial generator.
  696.    */
  697.  
  698.   if (init_flag==0) 
  699.   { /* no initialization needed */ 
  700.   }
  701.  
  702.   init_flag = 1;
  703. }
  704.  
  705.  
  706. /*
  707.  * Control points and info are shared by all contexts in the address space.
  708.  * The discard flag indicates whether the current control point data can be
  709.  * free()'d when new control points are given via glMap[12][fd].  It can't
  710.  * freed be when the current control points are also in a display list.
  711.  */
  712.  
  713.  
  714. /* Map 1, Vertex_3 */
  715. static GLuint Map1Vertex3order;
  716. static GLfloat Map1Vertex3u1, Map1Vertex3u2;
  717. static GLfloat *Map1Vertex3 = NULL;
  718. static GLboolean DiscardMap1Vertex3 = GL_FALSE;
  719.  
  720. /* Map 1, Vertex_4 */
  721. static GLuint Map1Vertex4order;
  722. static GLfloat Map1Vertex4u1, Map1Vertex4u2;
  723. static GLfloat *Map1Vertex4 = NULL;
  724. static GLboolean DiscardMap1Vertex4 = GL_FALSE;
  725.  
  726. /* Map 1, Index */
  727. static GLuint Map1Indexorder;
  728. static GLfloat Map1Indexu1, Map1Indexu2;
  729. static GLfloat *Map1Index = NULL;
  730. static GLboolean DiscardMap1Index = GL_FALSE;
  731.  
  732. /* Map 1, Color_4 */
  733. static GLuint Map1Color4order;
  734. static GLfloat Map1Color4u1, Map1Color4u2;
  735. static GLfloat *Map1Color4 = NULL;
  736. static GLboolean DiscardMap1Color4 = GL_FALSE;
  737.  
  738. /* Map 1, Normal */
  739. static GLuint Map1Normalorder;
  740. static GLfloat Map1Normalu1, Map1Normalu2;
  741. static GLfloat *Map1Normal = NULL;
  742. static GLboolean DiscardMap1Normal = GL_FALSE;
  743.  
  744. /* Map 1, Texture_1 */
  745. static GLuint Map1Texture1order;
  746. static GLfloat Map1Texture1u1, Map1Texture1u2;
  747. static GLfloat *Map1Texture1 = NULL;
  748. static GLboolean DiscardMap1Texture1 = GL_FALSE;
  749.  
  750. /* Map 1, Texture_2 */
  751. static GLuint Map1Texture2order;
  752. static GLfloat Map1Texture2u1, Map1Texture2u2;
  753. static GLfloat *Map1Texture2 = NULL;
  754. static GLboolean DiscardMap1Texture2 = GL_FALSE;
  755.  
  756. /* Map 1, Texture_3 */
  757. static GLuint Map1Texture3order;
  758. static GLfloat Map1Texture3u1, Map1Texture3u2;
  759. static GLfloat *Map1Texture3 = NULL;
  760. static GLboolean DiscardMap1Texture3 = GL_FALSE;
  761.  
  762. /* Map 1, Texture_4 */
  763. static GLuint Map1Texture4order;
  764. static GLfloat Map1Texture4u1, Map1Texture4u2;
  765. static GLfloat *Map1Texture4 = NULL;
  766. static GLboolean DiscardMap1Texture4 = GL_FALSE;
  767.  
  768.  
  769. /* Map 2, Vertex_3 */
  770. static GLuint Map2Vertex3uorder;
  771. static GLuint Map2Vertex3vorder;
  772. static GLfloat Map2Vertex3u1, Map2Vertex3u2;
  773. static GLfloat Map2Vertex3v1, Map2Vertex3v2;
  774. static GLfloat *Map2Vertex3 = NULL;
  775. static GLboolean DiscardMap2Vertex3 = GL_FALSE;
  776.  
  777. /* Map 2, Vertex_4 */
  778. static GLuint Map2Vertex4uorder;
  779. static GLuint Map2Vertex4vorder;
  780. static GLfloat Map2Vertex4u1, Map2Vertex4u2;
  781. static GLfloat Map2Vertex4v1, Map2Vertex4v2;
  782. static GLfloat *Map2Vertex4 = NULL;
  783. static GLboolean DiscardMap2Vertex4 = GL_FALSE;
  784.  
  785. /* Map 2, Index */
  786. static GLuint Map2Indexuorder;
  787. static GLuint Map2Indexvorder;
  788. static GLfloat Map2Indexu1, Map2Indexu2;
  789. static GLfloat Map2Indexv1, Map2Indexv2;
  790. static GLfloat *Map2Index = NULL;
  791. static GLboolean DiscardMap2Index = GL_FALSE;
  792.  
  793. /* Map 2, Color_4 */
  794. static GLuint Map2Color4uorder;
  795. static GLuint Map2Color4vorder;
  796. static GLfloat Map2Color4u1, Map2Color4u2;
  797. static GLfloat Map2Color4v1, Map2Color4v2;
  798. static GLfloat *Map2Color4 = NULL;
  799. static GLboolean DiscardMap2Color4 = GL_FALSE;
  800.  
  801. /* Map 2, Normal */
  802. static GLuint Map2Normaluorder;
  803. static GLuint Map2Normalvorder;
  804. static GLfloat Map2Normalu1, Map2Normalu2;
  805. static GLfloat Map2Normalv1, Map2Normalv2;
  806. static GLfloat *Map2Normal = NULL;
  807. static GLboolean DiscardMap2Normal = GL_FALSE;
  808.  
  809. /* Map 2, Texture_1 */
  810. static GLuint Map2Texture1uorder;
  811. static GLuint Map2Texture1vorder;
  812. static GLfloat Map2Texture1u1, Map2Texture1u2;
  813. static GLfloat Map2Texture1v1, Map2Texture1v2;
  814. static GLfloat *Map2Texture1 = NULL;
  815. static GLboolean DiscardMap2Texture1 = GL_FALSE;
  816.  
  817. /* Map 2, Texture_2 */
  818. static GLuint Map2Texture2uorder;
  819. static GLuint Map2Texture2vorder;
  820. static GLfloat Map2Texture2u1, Map2Texture2u2;
  821. static GLfloat Map2Texture2v1, Map2Texture2v2;
  822. static GLfloat *Map2Texture2 = NULL;
  823. static GLboolean DiscardMap2Texture2 = GL_FALSE;
  824.  
  825. /* Map 2, Texture_3 */
  826. static GLuint Map2Texture3uorder;
  827. static GLuint Map2Texture3vorder;
  828. static GLfloat Map2Texture3u1, Map2Texture3u2;
  829. static GLfloat Map2Texture3v1, Map2Texture3v2;
  830. static GLfloat *Map2Texture3 = NULL;
  831. static GLboolean DiscardMap2Texture3 = GL_FALSE;
  832.  
  833. /* Map 2, Texture_4 */
  834. static GLuint Map2Texture4uorder;
  835. static GLuint Map2Texture4vorder;
  836. static GLfloat Map2Texture4u1, Map2Texture4u2;
  837. static GLfloat Map2Texture4v1, Map2Texture4v2;
  838. static GLfloat *Map2Texture4 = NULL;
  839. static GLboolean DiscardMap2Texture4 = GL_FALSE;
  840.  
  841. /*
  842.  * Given a Map target, return a pointer to the corresponding Discard
  843.  * variable.
  844.  */
  845. static GLboolean *discard_target( GLenum target )
  846. {
  847.    switch (target) {
  848.       case GL_MAP1_VERTEX_3:        return &DiscardMap1Vertex3;
  849.       case GL_MAP1_VERTEX_4:        return &DiscardMap1Vertex4;
  850.       case GL_MAP1_INDEX:        return &DiscardMap1Index;
  851.       case GL_MAP1_COLOR_4:        return &DiscardMap1Color4;
  852.       case GL_MAP1_NORMAL:        return &DiscardMap1Normal;
  853.       case GL_MAP1_TEXTURE_COORD_1:    return &DiscardMap1Texture1;
  854.       case GL_MAP1_TEXTURE_COORD_2:    return &DiscardMap1Texture2;
  855.       case GL_MAP1_TEXTURE_COORD_3:    return &DiscardMap1Texture3;
  856.       case GL_MAP1_TEXTURE_COORD_4:    return &DiscardMap1Texture4;
  857.       case GL_MAP2_VERTEX_3:        return &DiscardMap2Vertex3;
  858.       case GL_MAP2_VERTEX_4:        return &DiscardMap2Vertex4;
  859.       case GL_MAP2_INDEX:        return &DiscardMap2Index;
  860.       case GL_MAP2_COLOR_4:        return &DiscardMap2Color4;
  861.       case GL_MAP2_NORMAL:        return &DiscardMap2Normal;
  862.       case GL_MAP2_TEXTURE_COORD_1:    return &DiscardMap2Texture1;
  863.       case GL_MAP2_TEXTURE_COORD_2:    return &DiscardMap2Texture2;
  864.       case GL_MAP2_TEXTURE_COORD_3:    return &DiscardMap2Texture3;
  865.       case GL_MAP2_TEXTURE_COORD_4:    return &DiscardMap2Texture4;
  866.       default:
  867.      gl_error( GL_INVALID_ENUM, "discard_target" );
  868.      return NULL;
  869.    }
  870. }
  871.  
  872. /**********************************************************************/
  873. /*                              Public                                */
  874. /**********************************************************************/
  875.  
  876. /*
  877.  * This function is called by the display list deallocator function to
  878.  * specify that a given set of control points are no longer needed.
  879.  * Under certain conditions, we can deallocate the control points memory,
  880.  * otherwise, we mark it as discard-able.
  881.  */
  882.  
  883. void gl_free_control_points( GLenum target, GLfloat *data )
  884. {
  885.    switch (target) {
  886.       case GL_MAP1_VERTEX_3:
  887.          if (data==Map1Vertex3) {
  888.         /* The control points in the display list are currently */
  889.         /* being used so we can mark them as discard-able. */
  890.         DiscardMap1Vertex3 = GL_TRUE;
  891.      }
  892.      else {
  893.         /* The control points in the display list are not currently */
  894.         /* being used. */
  895.         free( data );
  896.      }
  897.      break;
  898.       case GL_MAP1_VERTEX_4:
  899.          if (data==Map1Vertex4)
  900.         DiscardMap1Vertex4 = GL_TRUE;
  901.      else
  902.         free( data );
  903.      break;
  904.       case GL_MAP1_INDEX:
  905.          if (data==Map1Index)
  906.         DiscardMap1Index = GL_TRUE;
  907.      else
  908.         free( data );
  909.      break;
  910.       case GL_MAP1_COLOR_4:
  911.          if (data==Map1Vertex4)
  912.         DiscardMap1Vertex4 = GL_TRUE;
  913.      else
  914.         free( data );
  915.      break;
  916.       case GL_MAP1_NORMAL:
  917.          if (data==Map1Normal)
  918.         DiscardMap1Normal = GL_TRUE;
  919.      else
  920.         free( data );
  921.      break;
  922.       case GL_MAP1_TEXTURE_COORD_1:
  923.          if (data==Map1Texture1)
  924.         DiscardMap1Texture1 = GL_TRUE;
  925.      else
  926.         free( data );
  927.      break;
  928.       case GL_MAP1_TEXTURE_COORD_2:
  929.          if (data==Map1Texture2)
  930.         DiscardMap1Texture2 = GL_TRUE;
  931.      else
  932.         free( data );
  933.      break;
  934.       case GL_MAP1_TEXTURE_COORD_3:
  935.          if (data==Map1Texture3)
  936.         DiscardMap1Texture3 = GL_TRUE;
  937.      else
  938.         free( data );
  939.      break;
  940.       case GL_MAP1_TEXTURE_COORD_4:
  941.          if (data==Map1Texture4)
  942.         DiscardMap1Texture4 = GL_TRUE;
  943.      else
  944.         free( data );
  945.      break;
  946.       case GL_MAP2_VERTEX_3:
  947.          if (data==Map2Vertex3)
  948.         DiscardMap2Vertex3 = GL_TRUE;
  949.      else
  950.         free( data );
  951.      break;
  952.       case GL_MAP2_VERTEX_4:
  953.          if (data==Map2Vertex4)
  954.         DiscardMap2Vertex4 = GL_TRUE;
  955.      else
  956.         free( data );
  957.      break;
  958.       case GL_MAP2_INDEX:
  959.          if (data==Map2Index)
  960.         DiscardMap2Index = GL_TRUE;
  961.      else
  962.         free( data );
  963.      break;
  964.       case GL_MAP2_COLOR_4:
  965.          if (data==Map2Color4)
  966.         DiscardMap2Color4 = GL_TRUE;
  967.      else
  968.         free( data );
  969.      break;
  970.       case GL_MAP2_NORMAL:
  971.          if (data==Map2Normal)
  972.         DiscardMap2Normal = GL_TRUE;
  973.      else
  974.         free( data );
  975.      break;
  976.       case GL_MAP2_TEXTURE_COORD_1:
  977.          if (data==Map2Texture1)
  978.         DiscardMap2Texture1 = GL_TRUE;
  979.      else
  980.         free( data );
  981.      break;
  982.       case GL_MAP2_TEXTURE_COORD_2:
  983.          if (data==Map2Texture2)
  984.         DiscardMap2Texture2 = GL_TRUE;
  985.      else
  986.         free( data );
  987.      break;
  988.       case GL_MAP2_TEXTURE_COORD_3:
  989.          if (data==Map2Texture3)
  990.         DiscardMap2Texture3 = GL_TRUE;
  991.      else
  992.         free( data );
  993.      break;
  994.       case GL_MAP2_TEXTURE_COORD_4:
  995.          if (data==Map2Texture4)
  996.         DiscardMap2Texture4 = GL_TRUE;
  997.      else
  998.         free( data );
  999.      break;
  1000.       default:
  1001.      gl_error( GL_INVALID_ENUM, "gl_free_control_points" );
  1002.    }
  1003. }
  1004.  
  1005. /*
  1006.  * Internal glMap1{fd} function.  Note that points must be a contiguous
  1007.  * array of control points.
  1008.  */
  1009.  
  1010. void gl_map1( GLenum target, GLfloat u1, GLfloat u2, GLint stride,
  1011.           GLint order, const GLfloat *points )
  1012. {
  1013.    GLuint k;
  1014.  
  1015.    if (INSIDE_BEGIN_END) {
  1016.       gl_error( GL_INVALID_OPERATION, "glMap1" );
  1017.       return;
  1018.    }
  1019.  
  1020.    if (u1==u2) {
  1021.       gl_error( GL_INVALID_VALUE, "glMap1(u1,u2)" );
  1022.       return;
  1023.    }
  1024.  
  1025.    if (order<1 || order>MAX_EVAL_ORDER) {
  1026.       gl_error( GL_INVALID_VALUE, "glMap1(order)" );
  1027.       return;
  1028.    }
  1029.  
  1030.    k = components( target );
  1031.    if (k==0) {
  1032.       gl_error( GL_INVALID_ENUM, "glMap1(target)" );
  1033.    }
  1034.  
  1035.    if (stride < k) {
  1036.       gl_error( GL_INVALID_VALUE, "glMap1(stride)" );
  1037.       return;
  1038.    }
  1039.  
  1040.    switch (target) {
  1041.       case GL_MAP1_VERTEX_3:
  1042.          Map1Vertex3order = order;
  1043.      Map1Vertex3u1 = u1;
  1044.      Map1Vertex3u2 = u2;
  1045.      if (Map1Vertex3 && DiscardMap1Vertex3) {
  1046.         free( Map1Vertex3 );
  1047.      }
  1048.      DiscardMap1Vertex3 = GL_FALSE;
  1049.      Map1Vertex3 = (GLfloat *) points;
  1050.      break;
  1051.       case GL_MAP1_VERTEX_4:
  1052.          Map1Vertex4order = order;
  1053.      Map1Vertex4u1 = u1;
  1054.      Map1Vertex4u2 = u2;
  1055.      if (Map1Vertex4 && DiscardMap1Vertex4) {
  1056.         free( Map1Vertex4 );
  1057.      }
  1058.      DiscardMap1Vertex4 = GL_FALSE;
  1059.      Map1Vertex4 = (GLfloat *) points;
  1060.      break;
  1061.       case GL_MAP1_INDEX:
  1062.          Map1Indexorder = order;
  1063.      Map1Indexu1 = u1;
  1064.      Map1Indexu2 = u2;
  1065.      if (Map1Index && DiscardMap1Index) {
  1066.         free( Map1Index );
  1067.      }
  1068.      DiscardMap1Index = GL_FALSE;
  1069.      Map1Index = (GLfloat *) points;
  1070.      break;
  1071.       case GL_MAP1_COLOR_4:
  1072.          Map1Color4order = order;
  1073.      Map1Color4u1 = u1;
  1074.      Map1Color4u2 = u2;
  1075.      if (Map1Color4 && DiscardMap1Color4) {
  1076.         free( Map1Color4 );
  1077.      }
  1078.      DiscardMap1Color4 = GL_FALSE;
  1079.      Map1Color4 = (GLfloat *) points;
  1080.      break;
  1081.       case GL_MAP1_NORMAL:
  1082.          Map1Normalorder = order;
  1083.      Map1Normalu1 = u1;
  1084.      Map1Normalu2 = u2;
  1085.      if (Map1Normal && DiscardMap1Normal) {
  1086.         free( Map1Normal );
  1087.      }
  1088.      DiscardMap1Normal = GL_FALSE;
  1089.      Map1Normal = (GLfloat *) points;
  1090.      break;
  1091.       case GL_MAP1_TEXTURE_COORD_1:
  1092.          Map1Texture1order = order;
  1093.      Map1Texture1u1 = u1;
  1094.      Map1Texture1u2 = u2;
  1095.      if (Map1Texture1 && DiscardMap1Texture1) {
  1096.         free( Map1Texture1 );
  1097.      }
  1098.      DiscardMap1Texture1 = GL_FALSE;
  1099.      Map1Texture1 = (GLfloat *) points;
  1100.      break;
  1101.       case GL_MAP1_TEXTURE_COORD_2:
  1102.          Map1Texture2order = order;
  1103.      Map1Texture2u1 = u1;
  1104.      Map1Texture2u2 = u2;
  1105.      if (Map1Texture2 && DiscardMap1Texture2) {
  1106.         free( Map1Texture2 );
  1107.      }
  1108.      DiscardMap1Texture2 = GL_FALSE;
  1109.      Map1Texture2 = (GLfloat *) points;
  1110.      break;
  1111.       case GL_MAP1_TEXTURE_COORD_3:
  1112.          Map1Texture3order = order;
  1113.      Map1Texture3u1 = u1;
  1114.      Map1Texture3u2 = u2;
  1115.      if (Map1Texture3 && DiscardMap1Texture3) {
  1116.         free( Map1Texture3 );
  1117.      }
  1118.      DiscardMap1Texture3 = GL_FALSE;
  1119.      Map1Texture3 = (GLfloat *) points;
  1120.      break;
  1121.       case GL_MAP1_TEXTURE_COORD_4:
  1122.          Map1Texture4order = order;
  1123.      Map1Texture4u1 = u1;
  1124.      Map1Texture4u2 = u2;
  1125.      if (Map1Texture4 && DiscardMap1Texture4) {
  1126.         free( Map1Texture4 );
  1127.      }
  1128.      DiscardMap1Texture4 = GL_FALSE;
  1129.      Map1Texture4 = (GLfloat *) points;
  1130.      break;
  1131.       default:
  1132.          gl_error( GL_INVALID_ENUM, "glMap1(target)" );
  1133.    }
  1134. }
  1135.  
  1136. void glMap1f( GLenum target, GLfloat u1, GLfloat u2, GLint stride,
  1137.           GLint order, const GLfloat *points )
  1138. {
  1139.    float *p;
  1140.  
  1141.    p = copy_points1_f(target, stride, order, points);
  1142.  
  1143.    if (!p) {
  1144.       gl_error( GL_OUT_OF_MEMORY, "glMap1f" );
  1145.       return;
  1146.    }
  1147.  
  1148.    /* may be a new stride after copying control points */
  1149.    stride = components( target );
  1150.  
  1151.    if (CC.CompileFlag) {
  1152.       gl_save_map1( target, u1, u2, stride, order, p );
  1153.    }
  1154.    if (CC.ExecuteFlag) {
  1155.       gl_map1( target, u1, u2, stride, order, p );
  1156.       if (!CC.CompileFlag) {
  1157.      /* get pointer to the discard flag for the given target */
  1158.      GLboolean *discard = discard_target( target );
  1159.        /* the control points can be discarded when new ones are bound */
  1160.      *discard = GL_TRUE;
  1161.       }
  1162.    }
  1163. }
  1164.  
  1165. void glMap1d( GLenum target, GLdouble u1, GLdouble u2, GLint stride,
  1166.           GLint order, const GLdouble *points )
  1167. {
  1168.    float *p;
  1169.  
  1170.    p = copy_points1_d(target, stride, order, points);
  1171.  
  1172.    if (!p) {
  1173.       gl_error( GL_OUT_OF_MEMORY, "glMap1d" );
  1174.       return;
  1175.    }
  1176.  
  1177.    /* may be a new stride after copying control points */
  1178.    stride = components( target );
  1179.  
  1180.    if (CC.CompileFlag) {
  1181.       gl_save_map1( target, u1, u2, stride, order, p );
  1182.    }
  1183.    if (CC.ExecuteFlag) {
  1184.       gl_map1( target, u1, u2, stride, order, p );
  1185.       if (!CC.CompileFlag) {
  1186.      /* get pointer to the discard flag for the given target */
  1187.      GLboolean *discard = discard_target( target );
  1188.        /* the control points can be discarded when new ones are bound */
  1189.      *discard = GL_TRUE;
  1190.       }
  1191.    }
  1192. }
  1193.  
  1194.  
  1195.  
  1196.  
  1197. void gl_map2( GLenum target,
  1198.           GLfloat u1, GLfloat u2, GLint ustride, GLint uorder,
  1199.           GLfloat v1, GLfloat v2, GLint vstride, GLint vorder,
  1200.           const GLfloat *points )
  1201. {
  1202.    GLuint k;
  1203.  
  1204.    if (INSIDE_BEGIN_END) {
  1205.       gl_error( GL_INVALID_OPERATION, "glMap2" );
  1206.       return;
  1207.    }
  1208.  
  1209.    if (u1==u2) {
  1210.       gl_error( GL_INVALID_VALUE, "glMap2(u1,u2)" );
  1211.       return;
  1212.    }
  1213.  
  1214.    if (v1==v2) {
  1215.       gl_error( GL_INVALID_VALUE, "glMap2(v1,v2)" );
  1216.       return;
  1217.    }
  1218.  
  1219.    if (uorder<1 || uorder>MAX_EVAL_ORDER) {
  1220.       gl_error( GL_INVALID_VALUE, "glMap2(uorder)" );
  1221.       return;
  1222.    }
  1223.  
  1224.    if (vorder<1 || vorder>MAX_EVAL_ORDER) {
  1225.       gl_error( GL_INVALID_VALUE, "glMap2(vorder)" );
  1226.       return;
  1227.    }
  1228.  
  1229.    k = components( target );
  1230.    if (k==0) {
  1231.       gl_error( GL_INVALID_ENUM, "glMap2(target)" );
  1232.    }
  1233.  
  1234.    if (ustride < k) {
  1235.       gl_error( GL_INVALID_VALUE, "glMap2(ustride)" );
  1236.       return;
  1237.    }
  1238.    if (vstride < k) {
  1239.       gl_error( GL_INVALID_VALUE, "glMap2(vstride)" );
  1240.       return;
  1241.    }
  1242.  
  1243.    switch (target) {
  1244.       case GL_MAP2_VERTEX_3:
  1245.          Map2Vertex3uorder = uorder;
  1246.      Map2Vertex3u1 = u1;
  1247.      Map2Vertex3u2 = u2;
  1248.          Map2Vertex3vorder = vorder;
  1249.      Map2Vertex3v1 = v1;
  1250.      Map2Vertex3v2 = v2;
  1251.      if (Map2Vertex3 && DiscardMap2Vertex3) {
  1252.         free( Map2Vertex3 );
  1253.      }
  1254.      DiscardMap2Vertex3 = GL_FALSE;
  1255.      Map2Vertex3 = (GLfloat *) points;
  1256.      break;
  1257.       case GL_MAP2_VERTEX_4:
  1258.          Map2Vertex4uorder = uorder;
  1259.      Map2Vertex4u1 = u1;
  1260.      Map2Vertex4u2 = u2;
  1261.          Map2Vertex4vorder = vorder;
  1262.      Map2Vertex4v1 = v1;
  1263.      Map2Vertex4v2 = v2;
  1264.      if (Map2Vertex4 && DiscardMap2Vertex4) {
  1265.         free( Map2Vertex4 );
  1266.      }
  1267.      DiscardMap2Vertex4 = GL_FALSE;
  1268.      Map2Vertex4 = (GLfloat *) points;
  1269.      break;
  1270.       case GL_MAP2_INDEX:
  1271.          Map2Indexuorder = uorder;
  1272.      Map2Indexu1 = u1;
  1273.      Map2Indexu2 = u2;
  1274.          Map2Indexvorder = vorder;
  1275.      Map2Indexv1 = v1;
  1276.      Map2Indexv2 = v2;
  1277.      if (Map2Index && DiscardMap2Index) {
  1278.         free( Map2Index );
  1279.      }
  1280.      DiscardMap2Index = GL_FALSE;
  1281.      Map2Index = (GLfloat *) points;
  1282.      break;
  1283.       case GL_MAP2_COLOR_4:
  1284.          Map2Color4uorder = uorder;
  1285.      Map2Color4u1 = u1;
  1286.      Map2Color4u2 = u2;
  1287.          Map2Color4vorder = vorder;
  1288.      Map2Color4v1 = v1;
  1289.      Map2Color4v2 = v2;
  1290.      if (Map2Color4 && DiscardMap2Color4) {
  1291.         free( Map2Color4 );
  1292.      }
  1293.      DiscardMap2Color4 = GL_FALSE;
  1294.      Map2Color4 = (GLfloat *) points;
  1295.      break;
  1296.       case GL_MAP2_NORMAL:
  1297.          Map2Normaluorder = uorder;
  1298.      Map2Normalu1 = u1;
  1299.      Map2Normalu2 = u2;
  1300.          Map2Normalvorder = vorder;
  1301.      Map2Normalv1 = v1;
  1302.      Map2Normalv2 = v2;
  1303.      if (Map2Normal && DiscardMap2Normal) {
  1304.         free( Map2Normal );
  1305.      }
  1306.      DiscardMap2Normal = GL_FALSE;
  1307.      Map2Normal = (GLfloat *) points;
  1308.      break;
  1309.       case GL_MAP2_TEXTURE_COORD_1:
  1310.          Map2Texture1uorder = uorder;
  1311.      Map2Texture1u1 = u1;
  1312.      Map2Texture1u2 = u2;
  1313.          Map2Texture1vorder = vorder;
  1314.      Map2Texture1v1 = v1;
  1315.      Map2Texture1v2 = v2;
  1316.      if (Map2Texture1 && DiscardMap2Texture1) {
  1317.         free( Map2Texture1 );
  1318.      }
  1319.      DiscardMap2Texture1 = GL_FALSE;
  1320.      Map2Texture1 = (GLfloat *) points;
  1321.      break;
  1322.       case GL_MAP2_TEXTURE_COORD_2:
  1323.          Map2Texture2uorder = uorder;
  1324.      Map2Texture2u1 = u1;
  1325.      Map2Texture2u2 = u2;
  1326.          Map2Texture2vorder = vorder;
  1327.      Map2Texture2v1 = v1;
  1328.      Map2Texture2v2 = v2;
  1329.      if (Map2Texture2 && DiscardMap2Texture2) {
  1330.         free( Map2Texture2 );
  1331.      }
  1332.      DiscardMap2Texture2 = GL_FALSE;
  1333.      Map2Texture2 = (GLfloat *) points;
  1334.      break;
  1335.       case GL_MAP2_TEXTURE_COORD_3:
  1336.          Map2Texture3uorder = uorder;
  1337.      Map2Texture3u1 = u1;
  1338.      Map2Texture3u2 = u2;
  1339.          Map2Texture3vorder = vorder;
  1340.      Map2Texture3v1 = v1;
  1341.      Map2Texture3v2 = v2;
  1342.      if (Map2Texture3 && DiscardMap2Texture3) {
  1343.         free( Map2Texture3 );
  1344.      }
  1345.      DiscardMap2Texture3 = GL_FALSE;
  1346.      Map2Texture3 = (GLfloat *) points;
  1347.      break;
  1348.       case GL_MAP2_TEXTURE_COORD_4:
  1349.          Map2Texture4uorder = uorder;
  1350.      Map2Texture4u1 = u1;
  1351.      Map2Texture4u2 = u2;
  1352.          Map2Texture4vorder = vorder;
  1353.      Map2Texture4v1 = v1;
  1354.      Map2Texture4v2 = v2;
  1355.      if (Map2Texture4 && DiscardMap2Texture4) {
  1356.         free( Map2Texture4 );
  1357.      }
  1358.      DiscardMap2Texture4 = GL_FALSE;
  1359.      Map2Texture4 = (GLfloat *) points;
  1360.      break;
  1361.       default:
  1362.          gl_error( GL_INVALID_ENUM, "glMap1f(target)" );
  1363.    }
  1364.  
  1365. }
  1366.  
  1367.  
  1368.    
  1369. void glMap2f( GLenum target,
  1370.           GLfloat u1, GLfloat u2, GLint ustride, GLint uorder,
  1371.           GLfloat v1, GLfloat v2, GLint vstride, GLint vorder,
  1372.           const GLfloat *points )
  1373. {
  1374.    GLfloat *p;
  1375.  
  1376.    p = copy_points2_f(target, ustride, uorder, vstride, vorder, points);
  1377.  
  1378.    if (!p) {
  1379.       gl_error( GL_OUT_OF_MEMORY, "glMap2f" );
  1380.       return;
  1381.    }
  1382.  
  1383.    /* may be a new strides after copying control points */
  1384.    vstride = components( target );
  1385.    ustride = vorder * vstride;
  1386.  
  1387.    if (CC.CompileFlag) {
  1388.       gl_save_map2( target, u1, u2, ustride, uorder,
  1389.             v1, v2, vstride, vorder, p );
  1390.    }
  1391.    if (CC.ExecuteFlag) {
  1392.       gl_map2( target, u1, u2, ustride, uorder,
  1393.            v1, v2, vstride, vorder, p );
  1394.       if (!CC.CompileFlag) {
  1395.      /* get pointer to the discard flag for the given target */
  1396.      GLboolean *discard = discard_target( target );
  1397.        /* the control points can be discarded when new ones are bound */
  1398.      *discard = GL_TRUE;
  1399.       }
  1400.    }
  1401. }
  1402.  
  1403.  
  1404.  
  1405. void glMap2d( GLenum target,
  1406.           GLdouble u1, GLdouble u2, GLint ustride, GLint uorder,
  1407.           GLdouble v1, GLdouble v2, GLint vstride, GLint vorder,
  1408.           const GLdouble *points )
  1409. {
  1410.    GLfloat *p;
  1411.  
  1412.    p = copy_points2_d(target, ustride, uorder, vstride, vorder, points);
  1413.  
  1414.    if (!p) {
  1415.       gl_error( GL_OUT_OF_MEMORY, "glMap2d" );
  1416.       return;
  1417.    }
  1418.  
  1419.    /* may be a new strides after copying control points */
  1420.    vstride = components( target );
  1421.    ustride = vorder * vstride;
  1422.  
  1423.    if (CC.CompileFlag) {
  1424.       gl_save_map2( target, u1, u2, ustride, uorder,
  1425.             v1, v2, vstride, vorder, p );
  1426.    }
  1427.    if (CC.ExecuteFlag) {
  1428.       gl_map2( target, u1, u2, ustride, uorder,
  1429.            v1, v2, vstride, vorder, p );
  1430.       if (!CC.CompileFlag) {
  1431.      /* get pointer to the discard flag for the given target */
  1432.      GLboolean *discard = discard_target( target );
  1433.        /* the control points can be discarded when new ones are bound */
  1434.      *discard = GL_TRUE;
  1435.       }
  1436.    }
  1437. }
  1438.  
  1439.  
  1440.  
  1441. void glGetMapdv( GLenum target, GLenum query, GLdouble *v )
  1442. {
  1443.    GLuint i, n;
  1444.    GLfloat *data;
  1445.  
  1446.    switch (query) {
  1447.       case GL_COEFF:
  1448.      switch (target) {
  1449.         case GL_MAP1_COLOR_4:
  1450.            data = Map1Color4;
  1451.            n = Map1Color4order * 4;
  1452.            break;
  1453.         case GL_MAP1_INDEX:
  1454.            data = Map1Index;
  1455.            n = Map1Indexorder;
  1456.            break;
  1457.         case GL_MAP1_NORMAL:
  1458.            data = Map1Normal;
  1459.            n = Map1Normalorder * 3;
  1460.            break;
  1461.         case GL_MAP1_TEXTURE_COORD_1:
  1462.            data = Map1Texture1;
  1463.            n = Map1Texture1order * 1;
  1464.            break;
  1465.         case GL_MAP1_TEXTURE_COORD_2:
  1466.            data = Map1Texture2;
  1467.            n = Map1Texture2order * 2;
  1468.            break;
  1469.         case GL_MAP1_TEXTURE_COORD_3:
  1470.            data = Map1Texture3;
  1471.            n = Map1Texture3order * 3;
  1472.            break;
  1473.         case GL_MAP1_TEXTURE_COORD_4:
  1474.            data = Map1Texture4;
  1475.            n = Map1Texture4order * 4;
  1476.            break;
  1477.         case GL_MAP1_VERTEX_3:
  1478.            data = Map1Vertex3;
  1479.            n = Map1Vertex3order * 3;
  1480.            break;
  1481.         case GL_MAP1_VERTEX_4:
  1482.            data = Map1Vertex4;
  1483.            n = Map1Vertex4order * 4;
  1484.            break;
  1485.         case GL_MAP2_COLOR_4:
  1486.            data = Map2Color4;
  1487.            n = Map2Color4uorder * Map2Color4vorder * 4;
  1488.            break;
  1489.         case GL_MAP2_INDEX:
  1490.            data = Map2Index;
  1491.            n = Map2Indexuorder * Map2Indexvorder;
  1492.            break;
  1493.         case GL_MAP2_NORMAL:
  1494.            data = Map2Normal;
  1495.            n = Map2Normaluorder * Map2Normalvorder * 3;
  1496.            break;
  1497.         case GL_MAP2_TEXTURE_COORD_1:
  1498.            data = Map2Texture1;
  1499.            n = Map2Texture1uorder * Map2Texture1vorder * 1;
  1500.            break;
  1501.         case GL_MAP2_TEXTURE_COORD_2:
  1502.            data = Map2Texture2;
  1503.            n = Map2Texture2uorder * Map2Texture2vorder * 2;
  1504.            break;
  1505.         case GL_MAP2_TEXTURE_COORD_3:
  1506.            data = Map2Texture3;
  1507.            n = Map2Texture3uorder * Map2Texture3vorder * 3;
  1508.            break;
  1509.         case GL_MAP2_TEXTURE_COORD_4:
  1510.            data = Map2Texture4;
  1511.            n = Map2Texture4uorder * Map2Texture4vorder * 4;
  1512.            break;
  1513.         case GL_MAP2_VERTEX_3:
  1514.            data = Map2Vertex3;
  1515.            n = Map2Vertex3uorder * Map2Vertex3vorder * 3;
  1516.            break;
  1517.         case GL_MAP2_VERTEX_4:
  1518.            data = Map2Vertex4;
  1519.            n = Map2Vertex4uorder * Map2Vertex4vorder * 4;
  1520.            break;
  1521.         default:
  1522.            gl_error( GL_INVALID_ENUM, "glGetMapdv(target)" );
  1523.      }
  1524.      if (data) {
  1525.         for (i=0;i<n;i++) {
  1526.            v[i] = data[i];
  1527.         }
  1528.      }
  1529.          break;
  1530.       case GL_ORDER:
  1531.      switch (target) {
  1532.         case GL_MAP1_COLOR_4:
  1533.            *v = Map1Color4order;
  1534.            break;
  1535.         case GL_MAP1_INDEX:
  1536.            *v = Map1Indexorder;
  1537.            break;
  1538.         case GL_MAP1_NORMAL:
  1539.            *v = Map1Normalorder;
  1540.            break;
  1541.         case GL_MAP1_TEXTURE_COORD_1:
  1542.            *v = Map1Texture1order;
  1543.            break;
  1544.         case GL_MAP1_TEXTURE_COORD_2:
  1545.            *v = Map1Texture2order;
  1546.            break;
  1547.         case GL_MAP1_TEXTURE_COORD_3:
  1548.            *v = Map1Texture3order;
  1549.            break;
  1550.         case GL_MAP1_TEXTURE_COORD_4:
  1551.            *v = Map1Texture4order;
  1552.            break;
  1553.         case GL_MAP1_VERTEX_3:
  1554.            *v = Map1Vertex3order;
  1555.            break;
  1556.         case GL_MAP1_VERTEX_4:
  1557.            *v = Map1Vertex4order;
  1558.            break;
  1559.         case GL_MAP2_COLOR_4:
  1560.            v[0] = Map2Color4uorder;
  1561.            v[1] = Map2Color4vorder;
  1562.            break;
  1563.         case GL_MAP2_INDEX:
  1564.            v[0] = Map2Indexuorder;
  1565.            v[1] = Map2Indexvorder;
  1566.            break;
  1567.         case GL_MAP2_NORMAL:
  1568.            v[0] = Map2Normaluorder;
  1569.            v[1] = Map2Normalvorder;
  1570.            break;
  1571.         case GL_MAP2_TEXTURE_COORD_1:
  1572.            v[0] = Map2Texture1uorder;
  1573.            v[1] = Map2Texture1vorder;
  1574.            break;
  1575.         case GL_MAP2_TEXTURE_COORD_2:
  1576.            v[0] = Map2Texture2uorder;
  1577.            v[1] = Map2Texture2vorder;
  1578.            break;
  1579.         case GL_MAP2_TEXTURE_COORD_3:
  1580.            v[0] = Map2Texture3uorder;
  1581.            v[1] = Map2Texture3vorder;
  1582.            break;
  1583.         case GL_MAP2_TEXTURE_COORD_4:
  1584.            v[0] = Map2Texture4uorder;
  1585.            v[1] = Map2Texture4vorder;
  1586.            break;
  1587.         case GL_MAP2_VERTEX_3:
  1588.            v[0] = Map2Vertex3uorder;
  1589.            v[1] = Map2Vertex3vorder;
  1590.            break;
  1591.         case GL_MAP2_VERTEX_4:
  1592.            v[0] = Map2Vertex4uorder;
  1593.            v[1] = Map2Vertex4vorder;
  1594.            break;
  1595.         default:
  1596.            gl_error( GL_INVALID_ENUM, "glGetMapdv(target)" );
  1597.      }
  1598.          break;
  1599.       case GL_DOMAIN:
  1600.      switch (target) {
  1601.         case GL_MAP1_COLOR_4:
  1602.            v[0] = Map1Color4u1;
  1603.            v[1] = Map1Color4u2;
  1604.            break;
  1605.         case GL_MAP1_INDEX:
  1606.            v[0] = Map1Indexu1;
  1607.            v[1] = Map1Indexu2;
  1608.            break;
  1609.         case GL_MAP1_NORMAL:
  1610.            v[0] = Map1Normalu1;
  1611.            v[1] = Map1Normalu2;
  1612.            break;
  1613.         case GL_MAP1_TEXTURE_COORD_1:
  1614.            v[0] = Map1Texture1u1;
  1615.            v[1] = Map1Texture1u2;
  1616.            break;
  1617.         case GL_MAP1_TEXTURE_COORD_2:
  1618.            v[0] = Map1Texture2u1;
  1619.            v[1] = Map1Texture2u2;
  1620.            break;
  1621.         case GL_MAP1_TEXTURE_COORD_3:
  1622.            v[0] = Map1Texture3u1;
  1623.            v[1] = Map1Texture3u2;
  1624.            break;
  1625.         case GL_MAP1_TEXTURE_COORD_4:
  1626.            v[0] = Map1Texture4u1;
  1627.            v[1] = Map1Texture4u2;
  1628.            break;
  1629.         case GL_MAP1_VERTEX_3:
  1630.            v[0] = Map1Vertex3u1;
  1631.            v[1] = Map1Vertex3u2;
  1632.            break;
  1633.         case GL_MAP1_VERTEX_4:
  1634.            v[0] = Map1Vertex4u1;
  1635.            v[1] = Map1Vertex4u2;
  1636.            break;
  1637.         case GL_MAP2_COLOR_4:
  1638.            v[0] = Map2Color4u1;
  1639.            v[1] = Map2Color4u2;
  1640.            v[2] = Map2Color4v1;
  1641.            v[3] = Map2Color4v2;
  1642.            break;
  1643.         case GL_MAP2_INDEX:
  1644.            v[0] = Map2Indexu1;
  1645.            v[1] = Map2Indexu2;
  1646.            v[2] = Map2Indexv1;
  1647.            v[3] = Map2Indexv2;
  1648.            break;
  1649.         case GL_MAP2_NORMAL:
  1650.            v[0] = Map2Normalu1;
  1651.            v[1] = Map2Normalu2;
  1652.            v[2] = Map2Normalv1;
  1653.            v[3] = Map2Normalv2;
  1654.            break;
  1655.         case GL_MAP2_TEXTURE_COORD_1:
  1656.            v[0] = Map2Texture1u1;
  1657.            v[1] = Map2Texture1u2;
  1658.            v[2] = Map2Texture1v1;
  1659.            v[3] = Map2Texture1v2;
  1660.            break;
  1661.         case GL_MAP2_TEXTURE_COORD_2:
  1662.            v[0] = Map2Texture2u1;
  1663.            v[1] = Map2Texture2u2;
  1664.            v[2] = Map2Texture2v1;
  1665.            v[3] = Map2Texture2v2;
  1666.            break;
  1667.         case GL_MAP2_TEXTURE_COORD_3:
  1668.            v[0] = Map2Texture3u1;
  1669.            v[1] = Map2Texture3u2;
  1670.            v[2] = Map2Texture3v1;
  1671.            v[3] = Map2Texture3v2;
  1672.            break;
  1673.         case GL_MAP2_TEXTURE_COORD_4:
  1674.            v[0] = Map2Texture4u1;
  1675.            v[1] = Map2Texture4u2;
  1676.            v[2] = Map2Texture4v1;
  1677.            v[3] = Map2Texture4v2;
  1678.            break;
  1679.         case GL_MAP2_VERTEX_3:
  1680.            v[0] = Map2Vertex3u1;
  1681.            v[1] = Map2Vertex3u2;
  1682.            v[2] = Map2Vertex3v1;
  1683.            v[3] = Map2Vertex3v2;
  1684.            break;
  1685.         case GL_MAP2_VERTEX_4:
  1686.            v[0] = Map2Vertex4u1;
  1687.            v[1] = Map2Vertex4u2;
  1688.            v[2] = Map2Vertex4v1;
  1689.            v[3] = Map2Vertex4v2;
  1690.            break;
  1691.         default:
  1692.            gl_error( GL_INVALID_ENUM, "glGetMapdv(target)" );
  1693.      }
  1694.          break;
  1695.       default:
  1696.          gl_error( GL_INVALID_ENUM, "glGetMapdv(query)" );
  1697.    }
  1698. }
  1699.  
  1700.  
  1701. void glGetMapfv( GLenum target, GLenum query, GLfloat *v )
  1702. {
  1703.    GLuint i, n;
  1704.    GLfloat *data;
  1705.  
  1706.    switch (query) {
  1707.       case GL_COEFF:
  1708.      switch (target) {
  1709.         case GL_MAP1_COLOR_4:
  1710.            data = Map1Color4;
  1711.            n = Map1Color4order * 4;
  1712.            break;
  1713.         case GL_MAP1_INDEX:
  1714.            data = Map1Index;
  1715.            n = Map1Indexorder;
  1716.            break;
  1717.         case GL_MAP1_NORMAL:
  1718.            data = Map1Normal;
  1719.            n = Map1Normalorder * 3;
  1720.            break;
  1721.         case GL_MAP1_TEXTURE_COORD_1:
  1722.            data = Map1Texture1;
  1723.            n = Map1Texture1order * 1;
  1724.            break;
  1725.         case GL_MAP1_TEXTURE_COORD_2:
  1726.            data = Map1Texture2;
  1727.            n = Map1Texture2order * 2;
  1728.            break;
  1729.         case GL_MAP1_TEXTURE_COORD_3:
  1730.            data = Map1Texture3;
  1731.            n = Map1Texture3order * 3;
  1732.            break;
  1733.         case GL_MAP1_TEXTURE_COORD_4:
  1734.            data = Map1Texture4;
  1735.            n = Map1Texture4order * 4;
  1736.            break;
  1737.         case GL_MAP1_VERTEX_3:
  1738.            data = Map1Vertex3;
  1739.            n = Map1Vertex3order * 3;
  1740.            break;
  1741.         case GL_MAP1_VERTEX_4:
  1742.            data = Map1Vertex4;
  1743.            n = Map1Vertex4order * 4;
  1744.            break;
  1745.         case GL_MAP2_COLOR_4:
  1746.            data = Map2Color4;
  1747.            n = Map2Color4uorder * Map2Color4vorder * 4;
  1748.            break;
  1749.         case GL_MAP2_INDEX:
  1750.            data = Map2Index;
  1751.            n = Map2Indexuorder * Map2Indexvorder;
  1752.            break;
  1753.         case GL_MAP2_NORMAL:
  1754.            data = Map2Normal;
  1755.            n = Map2Normaluorder * Map2Normalvorder * 3;
  1756.            break;
  1757.         case GL_MAP2_TEXTURE_COORD_1:
  1758.            data = Map2Texture1;
  1759.            n = Map2Texture1uorder * Map2Texture1vorder * 1;
  1760.            break;
  1761.         case GL_MAP2_TEXTURE_COORD_2:
  1762.            data = Map2Texture2;
  1763.            n = Map2Texture2uorder * Map2Texture2vorder * 2;
  1764.            break;
  1765.         case GL_MAP2_TEXTURE_COORD_3:
  1766.            data = Map2Texture3;
  1767.            n = Map2Texture3uorder * Map2Texture3vorder * 3;
  1768.            break;
  1769.         case GL_MAP2_TEXTURE_COORD_4:
  1770.            data = Map2Texture4;
  1771.            n = Map2Texture4uorder * Map2Texture4vorder * 4;
  1772.            break;
  1773.         case GL_MAP2_VERTEX_3:
  1774.            data = Map2Vertex3;
  1775.            n = Map2Vertex3uorder * Map2Vertex3vorder * 3;
  1776.            break;
  1777.         case GL_MAP2_VERTEX_4:
  1778.            data = Map2Vertex4;
  1779.            n = Map2Vertex4uorder * Map2Vertex4vorder * 4;
  1780.            break;
  1781.         default:
  1782.            gl_error( GL_INVALID_ENUM, "glGetMapfv(target)" );
  1783.      }
  1784.      if (data) {
  1785.         for (i=0;i<n;i++) {
  1786.            v[i] = data[i];
  1787.         }
  1788.      }
  1789.          break;
  1790.       case GL_ORDER:
  1791.      switch (target) {
  1792.         case GL_MAP1_COLOR_4:
  1793.            *v = Map1Color4order;
  1794.            break;
  1795.         case GL_MAP1_INDEX:
  1796.            *v = Map1Indexorder;
  1797.            break;
  1798.         case GL_MAP1_NORMAL:
  1799.            *v = Map1Normalorder;
  1800.            break;
  1801.         case GL_MAP1_TEXTURE_COORD_1:
  1802.            *v = Map1Texture1order;
  1803.            break;
  1804.         case GL_MAP1_TEXTURE_COORD_2:
  1805.            *v = Map1Texture2order;
  1806.            break;
  1807.         case GL_MAP1_TEXTURE_COORD_3:
  1808.            *v = Map1Texture3order;
  1809.            break;
  1810.         case GL_MAP1_TEXTURE_COORD_4:
  1811.            *v = Map1Texture4order;
  1812.            break;
  1813.         case GL_MAP1_VERTEX_3:
  1814.            *v = Map1Vertex3order;
  1815.            break;
  1816.         case GL_MAP1_VERTEX_4:
  1817.            *v = Map1Vertex4order;
  1818.            break;
  1819.         case GL_MAP2_COLOR_4:
  1820.            v[0] = Map2Color4uorder;
  1821.            v[1] = Map2Color4vorder;
  1822.            break;
  1823.         case GL_MAP2_INDEX:
  1824.            v[0] = Map2Indexuorder;
  1825.            v[1] = Map2Indexvorder;
  1826.            break;
  1827.         case GL_MAP2_NORMAL:
  1828.            v[0] = Map2Normaluorder;
  1829.            v[1] = Map2Normalvorder;
  1830.            break;
  1831.         case GL_MAP2_TEXTURE_COORD_1:
  1832.            v[0] = Map2Texture1uorder;
  1833.            v[1] = Map2Texture1vorder;
  1834.            break;
  1835.         case GL_MAP2_TEXTURE_COORD_2:
  1836.            v[0] = Map2Texture2uorder;
  1837.            v[1] = Map2Texture2vorder;
  1838.            break;
  1839.         case GL_MAP2_TEXTURE_COORD_3:
  1840.            v[0] = Map2Texture3uorder;
  1841.            v[1] = Map2Texture3vorder;
  1842.            break;
  1843.         case GL_MAP2_TEXTURE_COORD_4:
  1844.            v[0] = Map2Texture4uorder;
  1845.            v[1] = Map2Texture4vorder;
  1846.            break;
  1847.         case GL_MAP2_VERTEX_3:
  1848.            v[0] = Map2Vertex3uorder;
  1849.            v[1] = Map2Vertex3vorder;
  1850.            break;
  1851.         case GL_MAP2_VERTEX_4:
  1852.            v[0] = Map2Vertex4uorder;
  1853.            v[1] = Map2Vertex4vorder;
  1854.            break;
  1855.         default:
  1856.            gl_error( GL_INVALID_ENUM, "glGetMapfv(target)" );
  1857.      }
  1858.          break;
  1859.       case GL_DOMAIN:
  1860.      switch (target) {
  1861.         case GL_MAP1_COLOR_4:
  1862.            v[0] = Map1Color4u1;
  1863.            v[1] = Map1Color4u2;
  1864.            break;
  1865.         case GL_MAP1_INDEX:
  1866.            v[0] = Map1Indexu1;
  1867.            v[1] = Map1Indexu2;
  1868.            break;
  1869.         case GL_MAP1_NORMAL:
  1870.            v[0] = Map1Normalu1;
  1871.            v[1] = Map1Normalu2;
  1872.            break;
  1873.         case GL_MAP1_TEXTURE_COORD_1:
  1874.            v[0] = Map1Texture1u1;
  1875.            v[1] = Map1Texture1u2;
  1876.            break;
  1877.         case GL_MAP1_TEXTURE_COORD_2:
  1878.            v[0] = Map1Texture2u1;
  1879.            v[1] = Map1Texture2u2;
  1880.            break;
  1881.         case GL_MAP1_TEXTURE_COORD_3:
  1882.            v[0] = Map1Texture3u1;
  1883.            v[1] = Map1Texture3u2;
  1884.            break;
  1885.         case GL_MAP1_TEXTURE_COORD_4:
  1886.            v[0] = Map1Texture4u1;
  1887.            v[1] = Map1Texture4u2;
  1888.            break;
  1889.         case GL_MAP1_VERTEX_3:
  1890.            v[0] = Map1Vertex3u1;
  1891.            v[1] = Map1Vertex3u2;
  1892.            break;
  1893.         case GL_MAP1_VERTEX_4:
  1894.            v[0] = Map1Vertex4u1;
  1895.            v[1] = Map1Vertex4u2;
  1896.            break;
  1897.         case GL_MAP2_COLOR_4:
  1898.            v[0] = Map2Color4u1;
  1899.            v[1] = Map2Color4u2;
  1900.            v[2] = Map2Color4v1;
  1901.            v[3] = Map2Color4v2;
  1902.            break;
  1903.         case GL_MAP2_INDEX:
  1904.            v[0] = Map2Indexu1;
  1905.            v[1] = Map2Indexu2;
  1906.            v[2] = Map2Indexv1;
  1907.            v[3] = Map2Indexv2;
  1908.            break;
  1909.         case GL_MAP2_NORMAL:
  1910.            v[0] = Map2Normalu1;
  1911.            v[1] = Map2Normalu2;
  1912.            v[2] = Map2Normalv1;
  1913.            v[3] = Map2Normalv2;
  1914.            break;
  1915.         case GL_MAP2_TEXTURE_COORD_1:
  1916.            v[0] = Map2Texture1u1;
  1917.            v[1] = Map2Texture1u2;
  1918.            v[2] = Map2Texture1v1;
  1919.            v[3] = Map2Texture1v2;
  1920.            break;
  1921.         case GL_MAP2_TEXTURE_COORD_2:
  1922.            v[0] = Map2Texture2u1;
  1923.            v[1] = Map2Texture2u2;
  1924.            v[2] = Map2Texture2v1;
  1925.            v[3] = Map2Texture2v2;
  1926.            break;
  1927.         case GL_MAP2_TEXTURE_COORD_3:
  1928.            v[0] = Map2Texture3u1;
  1929.            v[1] = Map2Texture3u2;
  1930.            v[2] = Map2Texture3v1;
  1931.            v[3] = Map2Texture3v2;
  1932.            break;
  1933.         case GL_MAP2_TEXTURE_COORD_4:
  1934.            v[0] = Map2Texture4u1;
  1935.            v[1] = Map2Texture4u2;
  1936.            v[2] = Map2Texture4v1;
  1937.            v[3] = Map2Texture4v2;
  1938.            break;
  1939.         case GL_MAP2_VERTEX_3:
  1940.            v[0] = Map2Vertex3u1;
  1941.            v[1] = Map2Vertex3u2;
  1942.            v[2] = Map2Vertex3v1;
  1943.            v[3] = Map2Vertex3v2;
  1944.            break;
  1945.         case GL_MAP2_VERTEX_4:
  1946.            v[0] = Map2Vertex4u1;
  1947.            v[1] = Map2Vertex4u2;
  1948.            v[2] = Map2Vertex4v1;
  1949.            v[3] = Map2Vertex4v2;
  1950.            break;
  1951.         default:
  1952.            gl_error( GL_INVALID_ENUM, "glGetMapfv(target)" );
  1953.      }
  1954.          break;
  1955.       default:
  1956.          gl_error( GL_INVALID_ENUM, "glGetMapfv(query)" );
  1957.    }
  1958. }
  1959.  
  1960.  
  1961. void glGetMapiv( GLenum target, GLenum query, GLint *v )
  1962. {
  1963.    GLuint i, n;
  1964.    GLfloat *data;
  1965.  
  1966.    switch (query) {
  1967.       case GL_COEFF:
  1968.      switch (target) {
  1969.         case GL_MAP1_COLOR_4:
  1970.            data = Map1Color4;
  1971.            n = Map1Color4order * 4;
  1972.            break;
  1973.         case GL_MAP1_INDEX:
  1974.            data = Map1Index;
  1975.            n = Map1Indexorder;
  1976.            break;
  1977.         case GL_MAP1_NORMAL:
  1978.            data = Map1Normal;
  1979.            n = Map1Normalorder * 3;
  1980.            break;
  1981.         case GL_MAP1_TEXTURE_COORD_1:
  1982.            data = Map1Texture1;
  1983.            n = Map1Texture1order * 1;
  1984.            break;
  1985.         case GL_MAP1_TEXTURE_COORD_2:
  1986.            data = Map1Texture2;
  1987.            n = Map1Texture2order * 2;
  1988.            break;
  1989.         case GL_MAP1_TEXTURE_COORD_3:
  1990.            data = Map1Texture3;
  1991.            n = Map1Texture3order * 3;
  1992.            break;
  1993.         case GL_MAP1_TEXTURE_COORD_4:
  1994.            data = Map1Texture4;
  1995.            n = Map1Texture4order * 4;
  1996.            break;
  1997.         case GL_MAP1_VERTEX_3:
  1998.            data = Map1Vertex3;
  1999.            n = Map1Vertex3order * 3;
  2000.            break;
  2001.         case GL_MAP1_VERTEX_4:
  2002.            data = Map1Vertex4;
  2003.            n = Map1Vertex4order * 4;
  2004.            break;
  2005.         case GL_MAP2_COLOR_4:
  2006.            data = Map2Color4;
  2007.            n = Map2Color4uorder * Map2Color4vorder * 4;
  2008.            break;
  2009.         case GL_MAP2_INDEX:
  2010.            data = Map2Index;
  2011.            n = Map2Indexuorder * Map2Indexvorder;
  2012.            break;
  2013.         case GL_MAP2_NORMAL:
  2014.            data = Map2Normal;
  2015.            n = Map2Normaluorder * Map2Normalvorder * 3;
  2016.            break;
  2017.         case GL_MAP2_TEXTURE_COORD_1:
  2018.            data = Map2Texture1;
  2019.            n = Map2Texture1uorder * Map2Texture1vorder * 1;
  2020.            break;
  2021.         case GL_MAP2_TEXTURE_COORD_2:
  2022.            data = Map2Texture2;
  2023.            n = Map2Texture2uorder * Map2Texture2vorder * 2;
  2024.            break;
  2025.         case GL_MAP2_TEXTURE_COORD_3:
  2026.            data = Map2Texture3;
  2027.            n = Map2Texture3uorder * Map2Texture3vorder * 3;
  2028.            break;
  2029.         case GL_MAP2_TEXTURE_COORD_4:
  2030.            data = Map2Texture4;
  2031.            n = Map2Texture4uorder * Map2Texture4vorder * 4;
  2032.            break;
  2033.         case GL_MAP2_VERTEX_3:
  2034.            data = Map2Vertex3;
  2035.            n = Map2Vertex3uorder * Map2Vertex3vorder * 3;
  2036.            break;
  2037.         case GL_MAP2_VERTEX_4:
  2038.            data = Map2Vertex4;
  2039.            n = Map2Vertex4uorder * Map2Vertex4vorder * 4;
  2040.            break;
  2041.         default:
  2042.            gl_error( GL_INVALID_ENUM, "glGetMapiv(target)" );
  2043.      }
  2044.      if (data) {
  2045.         for (i=0;i<n;i++) {
  2046.            v[i] = ROUND(data[i]);
  2047.         }
  2048.      }
  2049.          break;
  2050.       case GL_ORDER:
  2051.      switch (target) {
  2052.         case GL_MAP1_COLOR_4:
  2053.            *v = Map1Color4order;
  2054.            break;
  2055.         case GL_MAP1_INDEX:
  2056.            *v = Map1Indexorder;
  2057.            break;
  2058.         case GL_MAP1_NORMAL:
  2059.            *v = Map1Normalorder;
  2060.            break;
  2061.         case GL_MAP1_TEXTURE_COORD_1:
  2062.            *v = Map1Texture1order;
  2063.            break;
  2064.         case GL_MAP1_TEXTURE_COORD_2:
  2065.            *v = Map1Texture2order;
  2066.            break;
  2067.         case GL_MAP1_TEXTURE_COORD_3:
  2068.            *v = Map1Texture3order;
  2069.            break;
  2070.         case GL_MAP1_TEXTURE_COORD_4:
  2071.            *v = Map1Texture4order;
  2072.            break;
  2073.         case GL_MAP1_VERTEX_3:
  2074.            *v = Map1Vertex3order;
  2075.            break;
  2076.         case GL_MAP1_VERTEX_4:
  2077.            *v = Map1Vertex4order;
  2078.            break;
  2079.         case GL_MAP2_COLOR_4:
  2080.            v[0] = Map2Color4uorder;
  2081.            v[1] = Map2Color4vorder;
  2082.            break;
  2083.         case GL_MAP2_INDEX:
  2084.            v[0] = Map2Indexuorder;
  2085.            v[1] = Map2Indexvorder;
  2086.            break;
  2087.         case GL_MAP2_NORMAL:
  2088.            v[0] = Map2Normaluorder;
  2089.            v[1] = Map2Normalvorder;
  2090.            break;
  2091.         case GL_MAP2_TEXTURE_COORD_1:
  2092.            v[0] = Map2Texture1uorder;
  2093.            v[1] = Map2Texture1vorder;
  2094.            break;
  2095.         case GL_MAP2_TEXTURE_COORD_2:
  2096.            v[0] = Map2Texture2uorder;
  2097.            v[1] = Map2Texture2vorder;
  2098.            break;
  2099.         case GL_MAP2_TEXTURE_COORD_3:
  2100.            v[0] = Map2Texture3uorder;
  2101.            v[1] = Map2Texture3vorder;
  2102.            break;
  2103.         case GL_MAP2_TEXTURE_COORD_4:
  2104.            v[0] = Map2Texture4uorder;
  2105.            v[1] = Map2Texture4vorder;
  2106.            break;
  2107.         case GL_MAP2_VERTEX_3:
  2108.            v[0] = Map2Vertex3uorder;
  2109.            v[1] = Map2Vertex3vorder;
  2110.            break;
  2111.         case GL_MAP2_VERTEX_4:
  2112.            v[0] = Map2Vertex4uorder;
  2113.            v[1] = Map2Vertex4vorder;
  2114.            break;
  2115.         default:
  2116.            gl_error( GL_INVALID_ENUM, "glGetMapiv(target)" );
  2117.      }
  2118.          break;
  2119.       case GL_DOMAIN:
  2120.      switch (target) {
  2121.         case GL_MAP1_COLOR_4:
  2122.            v[0] = ROUND(Map1Color4u1);
  2123.            v[1] = ROUND(Map1Color4u2);
  2124.            break;
  2125.         case GL_MAP1_INDEX:
  2126.            v[0] = ROUND(Map1Indexu1);
  2127.            v[1] = ROUND(Map1Indexu2);
  2128.            break;
  2129.         case GL_MAP1_NORMAL:
  2130.            v[0] = ROUND(Map1Normalu1);
  2131.            v[1] = ROUND(Map1Normalu2);
  2132.            break;
  2133.         case GL_MAP1_TEXTURE_COORD_1:
  2134.            v[0] = ROUND(Map1Texture1u1);
  2135.            v[1] = ROUND(Map1Texture1u2);
  2136.            break;
  2137.         case GL_MAP1_TEXTURE_COORD_2:
  2138.            v[0] = ROUND(Map1Texture2u1);
  2139.            v[1] = ROUND(Map1Texture2u2);
  2140.            break;
  2141.         case GL_MAP1_TEXTURE_COORD_3:
  2142.            v[0] = ROUND(Map1Texture3u1);
  2143.            v[1] = ROUND(Map1Texture3u2);
  2144.            break;
  2145.         case GL_MAP1_TEXTURE_COORD_4:
  2146.            v[0] = ROUND(Map1Texture4u1);
  2147.            v[1] = ROUND(Map1Texture4u2);
  2148.            break;
  2149.         case GL_MAP1_VERTEX_3:
  2150.            v[0] = ROUND(Map1Vertex3u1);
  2151.            v[1] = ROUND(Map1Vertex3u2);
  2152.            break;
  2153.         case GL_MAP1_VERTEX_4:
  2154.            v[0] = ROUND(Map1Vertex4u1);
  2155.            v[1] = ROUND(Map1Vertex4u2);
  2156.            break;
  2157.         case GL_MAP2_COLOR_4:
  2158.            v[0] = ROUND(Map2Color4u1);
  2159.            v[1] = ROUND(Map2Color4u2);
  2160.            v[2] = ROUND(Map2Color4v1);
  2161.            v[3] = ROUND(Map2Color4v2);
  2162.            break;
  2163.         case GL_MAP2_INDEX:
  2164.            v[0] = ROUND(Map2Indexu1);
  2165.            v[1] = ROUND(Map2Indexu2);
  2166.            v[2] = ROUND(Map2Indexv1);
  2167.            v[3] = ROUND(Map2Indexv2);
  2168.            break;
  2169.         case GL_MAP2_NORMAL:
  2170.            v[0] = ROUND(Map2Normalu1);
  2171.            v[1] = ROUND(Map2Normalu2);
  2172.            v[2] = ROUND(Map2Normalv1);
  2173.            v[3] = ROUND(Map2Normalv2);
  2174.            break;
  2175.         case GL_MAP2_TEXTURE_COORD_1:
  2176.            v[0] = ROUND(Map2Texture1u1);
  2177.            v[1] = ROUND(Map2Texture1u2);
  2178.            v[2] = ROUND(Map2Texture1v1);
  2179.            v[3] = ROUND(Map2Texture1v2);
  2180.            break;
  2181.         case GL_MAP2_TEXTURE_COORD_2:
  2182.            v[0] = ROUND(Map2Texture2u1);
  2183.            v[1] = ROUND(Map2Texture2u2);
  2184.            v[2] = ROUND(Map2Texture2v1);
  2185.            v[3] = ROUND(Map2Texture2v2);
  2186.            break;
  2187.         case GL_MAP2_TEXTURE_COORD_3:
  2188.            v[0] = ROUND(Map2Texture3u1);
  2189.            v[1] = ROUND(Map2Texture3u2);
  2190.            v[2] = ROUND(Map2Texture3v1);
  2191.            v[3] = ROUND(Map2Texture3v2);
  2192.            break;
  2193.         case GL_MAP2_TEXTURE_COORD_4:
  2194.            v[0] = ROUND(Map2Texture4u1);
  2195.            v[1] = ROUND(Map2Texture4u2);
  2196.            v[2] = ROUND(Map2Texture4v1);
  2197.            v[3] = ROUND(Map2Texture4v2);
  2198.            break;
  2199.         case GL_MAP2_VERTEX_3:
  2200.            v[0] = ROUND(Map2Vertex3u1);
  2201.            v[1] = ROUND(Map2Vertex3u2);
  2202.            v[2] = ROUND(Map2Vertex3v1);
  2203.            v[3] = ROUND(Map2Vertex3v2);
  2204.            break;
  2205.         case GL_MAP2_VERTEX_4:
  2206.            v[0] = ROUND(Map2Vertex4u1);
  2207.            v[1] = ROUND(Map2Vertex4u2);
  2208.            v[2] = ROUND(Map2Vertex4v1);
  2209.            v[3] = ROUND(Map2Vertex4v2);
  2210.            break;
  2211.         default:
  2212.            gl_error( GL_INVALID_ENUM, "glGetMapiv(target)" );
  2213.      }
  2214.          break;
  2215.       default:
  2216.          gl_error( GL_INVALID_ENUM, "glGetMapiv(query)" );
  2217.    }
  2218. }
  2219.  
  2220.  
  2221.  
  2222. void gl_evalcoord1(GLfloat u)
  2223. {
  2224.   GLfloat vertex[4];
  2225.   GLfloat index;
  2226.   GLfloat color[4];
  2227.   GLfloat normal[3];
  2228.   GLfloat texcoord[4];
  2229.   register GLfloat uu;
  2230.  
  2231.   /** Vertex **/
  2232.   if (CC.Eval.Map1Vertex4) 
  2233.   {
  2234.     uu = (u-Map1Vertex4u1) / (Map1Vertex4u2-Map1Vertex4u1);
  2235.     horner_bezier_curve(Map1Vertex4, vertex, uu, 4, Map1Vertex4order);
  2236.   }
  2237.   else if (CC.Eval.Map1Vertex3) 
  2238.   {
  2239.     uu = (u-Map1Vertex3u1) / (Map1Vertex3u2-Map1Vertex3u1);
  2240.     horner_bezier_curve(Map1Vertex3, vertex, uu, 3, Map1Vertex3order);
  2241.  
  2242.     vertex[3] = 1.0;
  2243.   }
  2244.  
  2245.   /** Color Index **/
  2246.   if (CC.Eval.Map1Index) 
  2247.   {
  2248.     uu = (u-Map1Indexu1) / (Map1Indexu2-Map1Indexu1);
  2249.     horner_bezier_curve(Map1Index, &index, uu, 1, Map1Indexorder);
  2250.   }
  2251.   else 
  2252.     index = (GLfloat) CC.Current.Index;
  2253.  
  2254.   /** Color **/
  2255.   if (CC.Eval.Map1Color4) 
  2256.   {
  2257.     uu = (u-Map1Color4u1) / (Map1Color4u2-Map1Color4u1);
  2258.     horner_bezier_curve(Map1Color4, color, uu, 4, Map1Color4order);
  2259.   }
  2260.   else 
  2261.   {
  2262.     color[0] = CC.Current.Color[0];
  2263.     color[1] = CC.Current.Color[1];
  2264.     color[2] = CC.Current.Color[2];
  2265.     color[3] = CC.Current.Color[3];
  2266.   }
  2267.  
  2268.   /** Normal Vector **/
  2269.   if (CC.Eval.Map1Normal) 
  2270.   {
  2271.     uu = (u-Map1Normalu1) / (Map1Normalu2-Map1Normalu1);
  2272.     horner_bezier_curve(Map1Normal, normal, uu, 3, Map1Normalorder);
  2273.   }
  2274.   else 
  2275.   {
  2276.     normal[0] = CC.Current.Normal[0];
  2277.     normal[1] = CC.Current.Normal[1];
  2278.     normal[2] = CC.Current.Normal[2];
  2279.   }
  2280.  
  2281.   /** Texture Coordinates **/
  2282.   if (CC.Eval.Map1TextureCoord4) 
  2283.   {
  2284.     uu = (u-Map1Texture4u1) / (Map1Texture4u2-Map1Texture4u1);
  2285.     horner_bezier_curve(Map1Texture4, texcoord, uu, 4, Map1Texture4order);
  2286.   }
  2287.   else if (CC.Eval.Map1TextureCoord3) 
  2288.   {
  2289.     uu = (u-Map1Texture3u1) / (Map1Texture3u2-Map1Texture3u1);
  2290.     horner_bezier_curve(Map1Texture3, texcoord, uu, 3, Map1Texture3order);
  2291.     texcoord[3] = 1.0;
  2292.   }
  2293.   else if (CC.Eval.Map1TextureCoord2) 
  2294.   {
  2295.     uu = (u-Map1Texture2u1) / (Map1Texture2u2-Map1Texture2u1);
  2296.     horner_bezier_curve(Map1Texture2, texcoord, uu, 2, Map1Texture2order);
  2297.     
  2298.     texcoord[2] = 0.0;
  2299.     texcoord[3] = 1.0;
  2300.   }
  2301.   else if (CC.Eval.Map1TextureCoord1) 
  2302.   {
  2303.     uu = (u-Map1Texture1u1) / (Map1Texture1u2-Map1Texture1u1);
  2304.     horner_bezier_curve(Map1Texture1, texcoord, uu, 1, Map1Texture1order);
  2305.     
  2306.     texcoord[1] = 0.0;
  2307.     texcoord[2] = 0.0;
  2308.     texcoord[3] = 1.0;
  2309.   }
  2310.   else 
  2311.   {
  2312.     texcoord[0] = CC.Current.TexCoord[0];
  2313.     texcoord[1] = CC.Current.TexCoord[1];
  2314.     texcoord[2] = CC.Current.TexCoord[2];
  2315.     texcoord[3] = CC.Current.TexCoord[3];
  2316.   }
  2317.   
  2318.   gl_eval_vertex( vertex, normal, color, index, texcoord );
  2319. }
  2320.  
  2321. void glEvalCoord1f( GLfloat u )
  2322. {
  2323.    if (CC.CompileFlag) {
  2324.       gl_save_evalcoord1( u );
  2325.    }
  2326.    if (CC.ExecuteFlag) {
  2327.       gl_evalcoord1( u );
  2328.    }
  2329. }
  2330.  
  2331.  
  2332. void glEvalCoord1fv( const GLfloat *u )
  2333. {
  2334.    if (CC.CompileFlag) {
  2335.       gl_save_evalcoord1( *u );
  2336.    }
  2337.    if (CC.ExecuteFlag) {
  2338.       gl_evalcoord1( *u );
  2339.    }
  2340. }
  2341.  
  2342.  
  2343. void glEvalCoord1d( GLdouble u )
  2344. {
  2345.    if (CC.CompileFlag) {
  2346.       gl_save_evalcoord1( (GLfloat) u );
  2347.    }
  2348.    if (CC.ExecuteFlag) {
  2349.       gl_evalcoord1( (GLfloat) u );
  2350.    }
  2351. }
  2352.  
  2353.  
  2354. void glEvalCoord1dv( const GLdouble *u )
  2355. {
  2356.    if (CC.CompileFlag) {
  2357.       gl_save_evalcoord1( (GLfloat) *u );
  2358.    }
  2359.    if (CC.ExecuteFlag) {
  2360.       gl_evalcoord1( (GLfloat) *u );
  2361.    }
  2362. }
  2363.  
  2364.  
  2365. void gl_evalcoord2( GLfloat u, GLfloat v )
  2366. {
  2367.    GLfloat vertex[4];
  2368.    GLfloat normal[3];
  2369.    GLfloat color[4];
  2370.    GLfloat texcoord[4];
  2371.    GLfloat index;
  2372.    register GLfloat uu, vv;
  2373.  
  2374. #define CROSS_PROD(n, u, v) \
  2375.   (n)[0] = (u)[1]*(v)[2] - (u)[2]*(v)[1]; \
  2376.   (n)[1] = (u)[2]*(v)[0] - (u)[0]*(v)[2]; \
  2377.   (n)[2] = (u)[0]*(v)[1] - (u)[1]*(v)[0]
  2378. #define NORMALIZE(n) \
  2379.   { GLfloat l = sqrt((n)[0]*(n)[0] + (n)[1]*n[1] + (n)[2]*(n)[2]); \
  2380.     if(l > 0.000001) { (n)[0]/=l; (n)[1]/=l; (n)[2]/=l; } }
  2381.  
  2382.    /** Vertex **/
  2383.    if(CC.Eval.Map2Vertex4) 
  2384.    {
  2385.      uu = (u-Map2Vertex4u1) / (Map2Vertex4u2-Map2Vertex4u1);
  2386.      vv = (v-Map2Vertex4v1) / (Map2Vertex4v2-Map2Vertex4v1);
  2387.  
  2388.      if (CC.Eval.AutoNormal)
  2389.      {
  2390.        GLfloat du[4], dv[4];
  2391.  
  2392.        de_casteljau_surf(Map2Vertex4, vertex, du, dv, uu, vv, 4,
  2393.              Map2Vertex4uorder, Map2Vertex4vorder);
  2394.  
  2395.        CROSS_PROD(normal, du, dv);
  2396.        NORMALIZE(normal);
  2397.      }
  2398.      else
  2399.        horner_bezier_surf(Map2Vertex4, vertex, uu, vv, 4,
  2400.               Map2Vertex4uorder, Map2Vertex4vorder);
  2401.    }
  2402.    else if (CC.Eval.Map2Vertex3) 
  2403.    {
  2404.      uu = (u-Map2Vertex3u1) / (Map2Vertex3u2-Map2Vertex3u1);
  2405.      vv = (v-Map2Vertex3v1) / (Map2Vertex3v2-Map2Vertex3v1);
  2406.  
  2407.      if (CC.Eval.AutoNormal)
  2408.      {
  2409.        GLfloat du[3], dv[3];
  2410.        de_casteljau_surf(Map2Vertex3, vertex, du, dv, uu, vv, 3,
  2411.              Map2Vertex3uorder, Map2Vertex3vorder);
  2412.  
  2413.        CROSS_PROD(normal, du, dv);
  2414.        NORMALIZE(normal);
  2415.      }
  2416.      else
  2417.        horner_bezier_surf(Map2Vertex3, vertex, uu, vv, 3,
  2418.               Map2Vertex3uorder, Map2Vertex3vorder);
  2419.  
  2420.      vertex[3] = 1.0;
  2421.    }
  2422. #undef NORMALIZE
  2423. #undef CROSS_PROD
  2424.    
  2425.    /** Color Index **/
  2426.    if (CC.Eval.Map2Index) 
  2427.    {
  2428.      uu = (u-Map2Indexu1) / (Map2Indexu2-Map2Indexu1);
  2429.      vv = (v-Map2Indexv1) / (Map2Indexv2-Map2Indexv1);
  2430.  
  2431.      horner_bezier_surf(Map2Index, &index, uu, vv, 1,
  2432.             Map2Indexuorder, Map2Indexvorder);
  2433.    }
  2434.    else 
  2435.      index = (GLfloat) CC.Current.Index;
  2436.  
  2437.    /** Color **/
  2438.    if (CC.Eval.Map2Color4) 
  2439.    {
  2440.      uu = (u-Map2Color4u1) / (Map2Color4u2-Map2Color4u1);
  2441.      vv = (v-Map2Color4v1) / (Map2Color4v2-Map2Color4v1);
  2442.  
  2443.      horner_bezier_surf(Map2Color4, color, uu, vv, 4,
  2444.             Map2Color4uorder, Map2Color4vorder);
  2445.    }
  2446.    else 
  2447.    {
  2448.       color[0] = CC.Current.Color[0];
  2449.       color[1] = CC.Current.Color[1];
  2450.       color[2] = CC.Current.Color[2];
  2451.       color[3] = CC.Current.Color[3];
  2452.    }
  2453.  
  2454.    /** Normal **/
  2455.    if(!CC.Eval.AutoNormal || (!CC.Eval.Map2Vertex3 && !CC.Eval.Map2Vertex4))
  2456.    {
  2457.      if (CC.Eval.Map2Normal) 
  2458.      {
  2459.        uu = (u-Map2Normalu1) / (Map2Normalu2-Map2Normalu1);
  2460.        vv = (v-Map2Normalv1) / (Map2Normalv2-Map2Normalv1);
  2461.  
  2462.        horner_bezier_surf(Map2Normal, normal, uu, vv, 3,
  2463.               Map2Normaluorder, Map2Normalvorder);
  2464.      }
  2465.      else 
  2466.      {
  2467.        normal[0] = CC.Current.Normal[0];
  2468.        normal[1] = CC.Current.Normal[1];
  2469.        normal[2] = CC.Current.Normal[2];
  2470.      }
  2471.    }
  2472.  
  2473.    /** Texture Coordinates **/
  2474.    if (CC.Eval.Map2TextureCoord4) 
  2475.    {
  2476.      uu = (u-Map2Texture4u1) / (Map2Texture4u2-Map2Texture4u1);
  2477.      vv = (v-Map2Texture4v1) / (Map2Texture4v2-Map2Texture4v1);
  2478.  
  2479.      horner_bezier_surf(Map2Texture4, texcoord, uu, vv, 4,
  2480.             Map2Texture4uorder, Map2Texture4vorder);
  2481.    }
  2482.    else if (CC.Eval.Map2TextureCoord3) 
  2483.    {
  2484.      uu = (u-Map2Texture3u1) / (Map2Texture3u2-Map2Texture3u1);
  2485.      vv = (v-Map2Texture3v1) / (Map2Texture3v2-Map2Texture3v1);
  2486.  
  2487.      horner_bezier_surf(Map2Texture3, texcoord, uu, vv, 3,
  2488.             Map2Texture3uorder, Map2Texture3vorder);
  2489.  
  2490.      texcoord[3] = 1.0;
  2491.    }
  2492.    else if (CC.Eval.Map2TextureCoord2) 
  2493.    {
  2494.      uu = (u-Map2Texture2u1) / (Map2Texture2u2-Map2Texture2u1);
  2495.      vv = (v-Map2Texture2v1) / (Map2Texture2v2-Map2Texture2v1);
  2496.  
  2497.      horner_bezier_surf(Map2Texture2, texcoord, uu, vv, 2,
  2498.             Map2Texture2uorder, Map2Texture2vorder);
  2499.  
  2500.      texcoord[2] = 0.0;
  2501.      texcoord[3] = 1.0;
  2502.    }
  2503.    else if (CC.Eval.Map2TextureCoord1) 
  2504.    {
  2505.      uu = (u-Map2Texture1u1) / (Map2Texture1u2-Map2Texture1u1);
  2506.      vv = (v-Map2Texture1v1) / (Map2Texture1v2-Map2Texture1v1);
  2507.  
  2508.      horner_bezier_surf(Map2Texture1, texcoord, uu, vv, 1,
  2509.             Map2Texture1uorder, Map2Texture1vorder);
  2510.  
  2511.      texcoord[1] = 0.0;
  2512.      texcoord[2] = 0.0;
  2513.      texcoord[3] = 1.0;
  2514.    }
  2515.    else 
  2516.    {
  2517.      texcoord[0] = CC.Current.TexCoord[0];
  2518.      texcoord[1] = CC.Current.TexCoord[1];
  2519.      texcoord[2] = CC.Current.TexCoord[2];
  2520.      texcoord[3] = CC.Current.TexCoord[3];
  2521.    }
  2522.  
  2523.    gl_eval_vertex( vertex, normal, color, index, texcoord );
  2524. }
  2525.  
  2526.  
  2527. void glEvalCoord2f( GLfloat u, GLfloat v )
  2528. {
  2529.    if (CC.CompileFlag) {
  2530.       gl_save_evalcoord2( u, v );
  2531.    }
  2532.    if (CC.ExecuteFlag) {
  2533.       gl_evalcoord2( u, v );
  2534.    }
  2535. }
  2536.  
  2537.  
  2538. void glEvalCoord2fv( const GLfloat *u )
  2539. {
  2540.    if (CC.CompileFlag) {
  2541.       gl_save_evalcoord2( u[0], u[1] );
  2542.    }
  2543.    if (CC.ExecuteFlag) {
  2544.       gl_evalcoord2( u[0], u[1] );
  2545.    }
  2546. }
  2547.  
  2548.  
  2549. void glEvalCoord2d( GLdouble u, GLdouble v )
  2550. {
  2551.    if (CC.CompileFlag) {
  2552.       gl_save_evalcoord2( (GLfloat) u, (GLfloat) v );
  2553.    }
  2554.    if (CC.ExecuteFlag) {
  2555.       gl_evalcoord2( (GLfloat) u, (GLfloat) v );
  2556.    }
  2557. }
  2558.  
  2559.  
  2560. void glEvalCoord2dv( const GLdouble *u )
  2561. {
  2562.    if (CC.CompileFlag) {
  2563.       gl_save_evalcoord2( (GLfloat) u[0], (GLfloat) u[1] );
  2564.    }
  2565.    if (CC.ExecuteFlag) {
  2566.       gl_evalcoord2( (GLfloat) u[0], (GLfloat) u[1] );
  2567.    }
  2568. }
  2569.  
  2570.  
  2571.  
  2572. void gl_mapgrid1( GLint un, GLfloat u1, GLfloat u2 )
  2573. {
  2574.    if (INSIDE_BEGIN_END) {
  2575.       gl_error( GL_INVALID_OPERATION, "glMapGrid1f" );
  2576.       return;
  2577.    }
  2578.    if (un<1) {
  2579.       gl_error( GL_INVALID_VALUE, "glMapGrid1f" );
  2580.       return;
  2581.    }
  2582.    CC.Eval.MapGrid1un = un;
  2583.    CC.Eval.MapGrid1u1 = u1;
  2584.    CC.Eval.MapGrid1u2 = u2;
  2585. }
  2586.  
  2587.  
  2588. void glMapGrid1f( GLint un, GLfloat u1, GLfloat u2 )
  2589. {
  2590.    if (CC.CompileFlag) {
  2591.       gl_save_mapgrid1( un, u1, u2 );
  2592.    }
  2593.    if (CC.ExecuteFlag) {
  2594.       gl_mapgrid1( un, u1, u2 );
  2595.    }
  2596. }
  2597.  
  2598.  
  2599. void glMapGrid1d( GLint un, GLdouble u1, GLdouble u2 )
  2600. {
  2601.    if (CC.CompileFlag) {
  2602.       gl_save_mapgrid1( un, (GLfloat) u1, (GLfloat) u2 );
  2603.    }
  2604.    if (CC.ExecuteFlag) {
  2605.       gl_mapgrid1( un, (GLfloat) u1, (GLfloat) u2 );
  2606.    }
  2607. }
  2608.  
  2609.  
  2610.  
  2611. void gl_mapgrid2( GLint un, GLfloat u1, GLfloat u2,
  2612.           GLint vn, GLfloat v1, GLfloat v2 )
  2613. {
  2614.    if (INSIDE_BEGIN_END) {
  2615.       gl_error( GL_INVALID_OPERATION, "glMapGrid2f" );
  2616.       return;
  2617.    }
  2618.    if (un<1) {
  2619.       gl_error( GL_INVALID_VALUE, "glMapGrid2f(un)" );
  2620.       return;
  2621.    }
  2622.    if (vn<1) {
  2623.       gl_error( GL_INVALID_VALUE, "glMapGrid2f(vn)" );
  2624.       return;
  2625.    }
  2626.    CC.Eval.MapGrid2un = un;
  2627.    CC.Eval.MapGrid2u1 = u1;
  2628.    CC.Eval.MapGrid2u2 = u2;
  2629.    CC.Eval.MapGrid2vn = vn;
  2630.    CC.Eval.MapGrid2v1 = v1;
  2631.    CC.Eval.MapGrid2v2 = v2;
  2632. }
  2633.  
  2634.  
  2635. void glMapGrid2f( GLint un, GLfloat u1, GLfloat u2,
  2636.           GLint vn, GLfloat v1, GLfloat v2 )
  2637. {
  2638.    if (CC.CompileFlag) {
  2639.       gl_save_mapgrid2( un, u1, u2, vn, v1, v2 );
  2640.    }
  2641.    if (CC.ExecuteFlag) {
  2642.       gl_mapgrid2( un, u1, u2, vn, v1, v2 );
  2643.    }
  2644. }
  2645.  
  2646.  
  2647. void glMapGrid2d( GLint un, GLdouble u1, GLdouble u2,
  2648.           GLint vn, GLdouble v1, GLdouble v2 )
  2649. {
  2650.    if (CC.CompileFlag) {
  2651.       gl_save_mapgrid2( un, (GLfloat) u1, (GLfloat) u2,
  2652.                 vn, (GLfloat) v1, (GLfloat) v2 );
  2653.    }
  2654.    if (CC.ExecuteFlag) {
  2655.       gl_mapgrid2( un, (GLfloat) u1, (GLfloat) u2,
  2656.            vn, (GLfloat) v1, (GLfloat) v2 );
  2657.    }
  2658. }
  2659.  
  2660.  
  2661.  
  2662. void glEvalPoint1( GLint i )
  2663. {
  2664.    if (CC.CompileFlag) {
  2665.       gl_save_evalpoint1( i );
  2666.    }
  2667.    if (CC.ExecuteFlag) {
  2668.       GLfloat u, du;
  2669.  
  2670.       if (i==0) {
  2671.      u = CC.Eval.MapGrid1u1;
  2672.       }
  2673.       else if (i==CC.Eval.MapGrid1un) {
  2674.      u = CC.Eval.MapGrid1u2;
  2675.       }
  2676.       else {
  2677.      du = (CC.Eval.MapGrid1u2 - CC.Eval.MapGrid1u1)
  2678.           / (GLfloat) CC.Eval.MapGrid1un;
  2679.      u = i * du + CC.Eval.MapGrid1u1;
  2680.       }
  2681.       gl_evalcoord1( u );
  2682.    }
  2683. }
  2684.  
  2685.  
  2686.  
  2687. void glEvalPoint2( GLint i, GLint j )
  2688. {
  2689.    if (CC.CompileFlag) {
  2690.       gl_save_evalpoint2( i, j );
  2691.    }
  2692.    if (CC.ExecuteFlag) {
  2693.       GLfloat u, du;
  2694.       GLfloat v, dv;
  2695.  
  2696.       if (i==0) {
  2697.      u = CC.Eval.MapGrid2u1;
  2698.       }
  2699.       else if (i==CC.Eval.MapGrid2un) {
  2700.      u = CC.Eval.MapGrid2u2;
  2701.       }
  2702.       else {
  2703.      du = (CC.Eval.MapGrid2u2 - CC.Eval.MapGrid2u1)
  2704.            / (GLfloat) CC.Eval.MapGrid2un;
  2705.      u = i * du + CC.Eval.MapGrid2u1;
  2706.       }
  2707.  
  2708.       if (j==0) {
  2709.      v = CC.Eval.MapGrid2v1;
  2710.       }
  2711.       else if (j==CC.Eval.MapGrid2vn) {
  2712.      v = CC.Eval.MapGrid2v2;
  2713.       }
  2714.       else {
  2715.      dv = (CC.Eval.MapGrid2v2 - CC.Eval.MapGrid2v1)
  2716.            / (GLfloat) CC.Eval.MapGrid2vn;
  2717.      v = j * dv + CC.Eval.MapGrid2v1;
  2718.       }
  2719.  
  2720.       gl_evalcoord2( u, v );
  2721.    }
  2722. }
  2723.  
  2724.  
  2725.  
  2726. void glEvalMesh1( GLenum mode, GLint i1, GLint i2 )
  2727. {
  2728.    GLint i;
  2729.    GLfloat u, du;
  2730.    GLenum prim;
  2731.  
  2732.    if (CC.CompileFlag) {
  2733.       gl_save_evalmesh1( mode, i1, i2 );
  2734.    }
  2735.    if (CC.ExecuteFlag) {
  2736.  
  2737.       if (INSIDE_BEGIN_END) {
  2738.      gl_error( GL_INVALID_OPERATION, "glEvalMesh1" );
  2739.      return;
  2740.       }
  2741.  
  2742.       switch (mode) {
  2743.      case GL_POINT:
  2744.         prim = GL_POINTS;
  2745.         break;
  2746.      case GL_LINE:
  2747.         prim = GL_LINE_STRIP;
  2748.         break;
  2749.      default:
  2750.         gl_error( GL_INVALID_ENUM, "glEvalMesh1(mode)" );
  2751.         return;
  2752.       }
  2753.  
  2754.       du = (CC.Eval.MapGrid1u2 - CC.Eval.MapGrid1u1)
  2755.            / (GLfloat) CC.Eval.MapGrid1un;
  2756.  
  2757.       gl_begin( prim );
  2758.       for (i=i1;i<=i2;i++) {
  2759.      if (i==0) {
  2760.         u = CC.Eval.MapGrid1u1;
  2761.      }
  2762.      else if (i==CC.Eval.MapGrid1un) {
  2763.         u = CC.Eval.MapGrid1u2;
  2764.      }
  2765.      else {
  2766.         u = i * du + CC.Eval.MapGrid1u1;
  2767.      }
  2768.      gl_evalcoord1( u );
  2769.       }
  2770.       gl_end();
  2771.    }
  2772. }
  2773.  
  2774.  
  2775.  
  2776. void glEvalMesh2( GLenum mode, GLint i1, GLint i2, GLint j1, GLint j2 )
  2777. {
  2778.    GLint i, j;
  2779.    GLfloat u, du, v, dv, v1, v2;
  2780.  
  2781.    if (CC.CompileFlag) {
  2782.       gl_save_evalmesh2( mode, i1, i2, j1, j2 );
  2783.    }
  2784.    if (CC.ExecuteFlag) {
  2785.  
  2786.       if (INSIDE_BEGIN_END) {
  2787.      gl_error( GL_INVALID_OPERATION, "glEvalMesh2" );
  2788.      return;
  2789.       }
  2790.  
  2791.       du = (CC.Eval.MapGrid2u2 - CC.Eval.MapGrid2u1)
  2792.            / (GLfloat) CC.Eval.MapGrid2un;
  2793.       dv = (CC.Eval.MapGrid2v2 - CC.Eval.MapGrid2v1)
  2794.            / (GLfloat) CC.Eval.MapGrid2vn;
  2795.  
  2796. #define I_TO_U( I, U )                \
  2797.        if ((I)==0) {                   \
  2798.           U = CC.Eval.MapGrid2u1;        \
  2799.        }                    \
  2800.        else if ((I)==CC.Eval.MapGrid2un) {    \
  2801.           U = CC.Eval.MapGrid2u2;        \
  2802.        }                    \
  2803.        else {                \
  2804.           U = (I) * du + CC.Eval.MapGrid2u1;\
  2805.        }
  2806.  
  2807. #define J_TO_V( J, V )                \
  2808.        if ((J)==0) {            \
  2809.           V = CC.Eval.MapGrid2v1;        \
  2810.        }                    \
  2811.        else if ((J)==CC.Eval.MapGrid2vn) {    \
  2812.           V = CC.Eval.MapGrid2v2;        \
  2813.        }                    \
  2814.        else {                \
  2815.           V = (J) * dv + CC.Eval.MapGrid2v1;\
  2816.        }
  2817.  
  2818.       switch (mode) {
  2819.      case GL_POINT:
  2820.         gl_begin( GL_POINTS );
  2821.         for (j=j1;j<=j2;j++) {
  2822.            J_TO_V( j, v );
  2823.            for (i=i1;i<=i2;i++) {
  2824.           I_TO_U( i, u );
  2825.           gl_evalcoord2( u, v );
  2826.            }
  2827.         }
  2828.         gl_end();
  2829.         break;
  2830.      case GL_LINE:
  2831.         for (j=j1;j<=j2;j++) {
  2832.            J_TO_V( j, v );
  2833.            gl_begin( GL_LINE_STRIP );
  2834.            for (i=i1;i<=i2;i++) {
  2835.           I_TO_U( i, u );
  2836.           gl_evalcoord2( u, v );
  2837.            }
  2838.            gl_end();
  2839.         }
  2840.         for (i=i1;i<=i2;i++) {
  2841.            I_TO_U( i, u );
  2842.            gl_begin( GL_LINE_STRIP );
  2843.            for (j=j1;j<=j2;j++) {
  2844.           J_TO_V( j, v );
  2845.           gl_evalcoord2( u, v );
  2846.            }
  2847.            gl_end();
  2848.         }
  2849.         break;
  2850.      case GL_FILL:
  2851.         for (j=j1;j<j2;j++) {
  2852.            /* NOTE: a quad strip can't be used because the four */
  2853.            /* can't be guaranteed to be coplanar! */
  2854.            gl_begin( GL_TRIANGLE_STRIP );
  2855.            J_TO_V( j, v1 );
  2856.            J_TO_V( j+1, v2 );
  2857.            for (i=i1;i<=i2;i++) {
  2858.           I_TO_U( i, u );
  2859.           gl_evalcoord2( u, v1 );
  2860.           gl_evalcoord2( u, v2 );
  2861.            }
  2862.            gl_end();
  2863.         }
  2864.         break;
  2865.      default:
  2866.         gl_error( GL_INVALID_ENUM, "glEvalMesh2(mode)" );
  2867.         return;
  2868.       }
  2869.  
  2870. #undef I_TO_U
  2871. #undef J_TO_V
  2872.    }
  2873. }
  2874.  
  2875.